The Send Email plugin lets you send an email from within an ExpressionEngine template without the user submitting a form.
Compatibility
Compatible with both EE v1.x and v2.x.
Installation
EE v1.x
Place the pi.send_email.php file in the /plugins directory.
EE v2.x
Create in the /third_party directory a directory /send_email, then place the pi.send_email.php in there.
Required Parameters
to
This is the only required parameter, the email address that the email will go to.
Optional Parameters
from_email
The email address that will appear in the email’s From area. If using, also requires the from_name parameter.
from_name
The name address that will appear in the email’s From area. If using, also requires the from_email parameter.
subject
The email’s subject. If left empty, the default is “Email from [site_name]”.
mailtype
Either “html” or “plain”. Default is “plain”. Currently working in EE v2.x only.
parse
This parameter is available to all EE plugins. When set with a value of “inward” it allows the plugin to contain other plugins.
Variables
username, screen_name, member_id, email, ip_address
Example
{exp:send_email
from_name="Joe Kissel"
from_email="joe@kisselmail.org"
to="mail@wackysillyhairpieces.net"
subject="Hairpiece for Pico"
}
Dear Wacky Silly Hairpieces,
Can you do something about {screen_name}s hair? Though he does got to get back to work.
Thank you,
Joe Kissel
{/exp:send_email}
Changelog
v1.4 (2012 Jan 26)
- Replaced code with contribution from Tiffany in comments
- Added username, screen_name, member_id, email, ip_address parameters
v1.2 (2011 May 3)
- Forced substitution of “&+47;” to “/” in email body
v1.1 (2010 Mar 19)
- Added mailtype parameter
Roadmap
- add support for variables within emails
Thu 15 Apr ’10
2:54pm
Adam Khan
Sophia, try parse=“inward”. If that doesn’t work, I’ll have to work on it to get variables working.
Thu 15 Apr ’10
9:14pm
Sophia Browne
Hi, I tried the parse=inward and that didn’t work either.
Fri 16 Apr ’10
8:30pm
Adam Khan
Sophia, thanks for trying. I’ve added that to the plugin’s roadmap. Can’t say with confidence when exactly I’ll get to it though.
Fri 16 Apr ’10
11:14pm
Sophia Browne
Ok, that’s no problem. I will just workaround it.
Thanks anyways.
Tue 20 Apr ’10
10:27pm
Kurt
I’m very interested in this. I’ve been asked to create a sort of tell-a-friend/e-card that self submits after a freeform is submitted. This might be a great way to make that happen.
Tue 4 May ’10
5:45pm
Nick Benson
I’m getting the following error on my EE 2 site, any thoughts?
————————-
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant PATH_CORE - assumed ‘PATH_CORE’
Filename: send_email/pi.send_email.php
Line Number: 74
Sun 11 Jul ’10
1:56am
jimboJ
Any news following on from Nick Benson’s comment above? Having the same issue…
Tue 10 Aug ’10
8:50pm
Kyle Batson
I have a request that allows using conditionals inside the message. I’m populating the message field with some custom fields, and if that custom field is not present, I don’t want it to show up. Something simple like {if custom_field}Content here{/if}
Also, might you know why having ‘http://’ in the message field outputs as encoded HTML character entities instead? Is there a way this can be switched from within the plugin?
Thanks.
Wed 25 Aug ’10
6:08am
Adam Khan
Sorry for not responding, people, I’ve been a bit swamped and haven’t had time to address issues on the free plugins.
Nick and JimboJ, I haven’t yet figured out why the PHP notice is happening, sorry!
Kyle, the encoding is happening within EE’s built-in functions that the plugin’s calling—I’ll have to look further to see how to disable that.
Wed 29 Sep ’10
2:42pm
Sophia Browne
Hi,
I added to the send email plugin since I had the same HTML character entities problem.
I added a function from the Regular expressions class to the -> $E->message($REGX->unhtmlentities($message)); Don’t forget to call the class -> global $REGX; // EEv1 syntax.
The unhtmlentities function takes a string and returns with all entities turned into their characters. http://expressionengine.com/legacy_docs/development/reference/regex.html
In a bit of a hurry, so I have to keep this short, hope this helps!
Mon 10 Jan ’11
12:38pm
Adam Khan
Sophie, it’s months later, my apologies for leaving you in the lurch there, presume you got it fixed!
Mon 10 Jan ’11
5:13pm
Sophia Pitt-Browne
Yes Adam, I did!
Thu 17 Mar ’11
6:51am
Stuart
Re: Use of undefined constant PATH_CORE
Looking at the file and the structure of 1.6 V 2.0.1 that the file it’s referencing “core.email” no longer exists in 2.1.X
No idea how to amend or what to amend to :(
Fri 22 Apr ’11
1:41pm
James
I’m getting the same PHP error as Nick, did anyone ever find a way round it?
Tue 24 May ’11
3:11pm
Jim
Any idea when yo might add the functionality for variables?
Tue 2 Aug ’11
3:34pm
Tiffany
I got this to work on EE 2.1.3 by replacing the send email code with this:
// Send email
$this->EE->load->library(‘email’);
$this->EE->email->initialize();
if ($from_email && $from_name)
{
$this->EE->email->from($from_email, $from_name);
}
else
{
$this->EE->email->from($PREFS->ini(‘webmaster_email’), $PREFS->ini(‘webmaster_name’));
}
$this->EE->email->to($to);
if ($subject)
{
$this->EE->email->subject($subject);
}
else
{
$this->EE->email->subject( “Email from ” . $PREFS->ini(‘site_name’) );
}
$this->EE->email->message($message);
$this->EE->email->Send();
Mon 23 Jan ’12
10:43pm
Adam Khan
Tiffany, a very belated thanks for fixing the plugin. Working for me on EE2. Not sure now though on EE1, will have to check.
Wed 7 Mar ’12
8:33pm
Toby Callinan
Just wondering…
Does this plugin work when it’s submit? It mentions that it works without submitting a form. Does that mean I can set up a cron job that will then just send an email?
I’m tring to find a method to send emails after a query I the DB that pulls out certain users - ths might be perfect!
Wed 7 Mar ’12
8:39pm
Adam Khan
Toby,
No form involved, just sends an email when the template containing the tag is loaded. Nice when loaded with ajax.
Tue 10 Apr ’12
3:32pm
Rob Stokes
If I understand correctly ... the from name, from email address, to email address and subject all have to be hard-coded into the template. It is not possible, for example, to look at a channel entry and pull out the details from there?
I was hoping to use this plug-in to send a “thank you” notification email to a user after they had filled in a form (with which I am using Safecracker to store the entered details in a channel) on the site. The “to” email address at the very least will be dynamic.
Can I not do this with this plug-in?
Tue 10 Apr ’12
3:42pm
Rob Stokes
Thought I’d better say ... I’ve tried putting the {exp:channel:entries} code directly within the send_email tag, as well as calling the result via a snippet and an embed, but none worked. Works fine when I hard-code the details.
Fri 11 May ’12
3:22pm
Michael Rog
Rob, try wrapping the Send_email plugin INSIDE of the Channel:Entries tag, and use parse=“inward” on the outer tag. Then you can use the email address variables from your entries as the parameters of Send_email.
Thu 21 Jun ’12
5:47pm
Laurence Cope
This is a great little plugin. I am combining it with EEI_TCPDF to generate a PDF from a template then saves it, and uses Send Email to attach and email it.
So I have modified your file to add attach, I think you should update it, its very useful…
$attachment = $TMPL->fetch_param(‘attachment’);
// Attach attachment
if($attachment != ‘’)
{
$this->EE->email->attach($attachment);
}
Fri 22 Jun ’12
12:52pm
Adam Khan
Thanks Laurence, will add that in for next release!
Fri 28 Sep ’12
4:30am
Craig Allen
I’ve tried it with mailtype=“html”, but all the html is being displayed in email clients. What might be the cause of this? I’m using EE 2.5.2
Thu 4 Oct ’12
3:08pm
Kevin Fodness
Craig - I had the same problem, and discovered that the logic to handle mailtype was not in the plugin. I solved it by adding the following lines:
1) Add this after $subject = $TMPL->fetch_param(‘subject’);
$mailtype = $TMPL->fetch_param(‘mailtype’);
2) Add this after $this->EE->load->library(‘email’);
if ($mailtype == ‘html’)
{
$this->EE->email->mailtype =‘html’;
}
Thu 15 Apr ’10
1:21pm
Sophia Browne
Does this plugin allow dynamic variables? I am trying to use {site_name} and {webmaster_email} and they are not being processed.