E-mail component is available in cakePHP . It is very easy to send email from that.
First we should include Email component in our controller.
(i.e) app/controller/example_controller.php
var $components = array('Email');
Then include below in your code
function email(){
$this->Email->to = 'recipent@gmail.com';
$this->Email->subject = 'Include your subject';
$this->Email->from = 'youremail@gmail.com';
$this->Email->template = 'template'; // file name template.ctp will be included in /views/elements/email/text/template.ctp
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'youremail@gmail.com',
'password'=>'yourpassword',
);
$this->Email->delivery = 'smtp';
if ($this->Email->send()) {
return true;
} else {
echo $this->Email->smtpError;
}
}
Dont forget to include template.ctp in /views/elements/email/text/template.ctp
. It is very easy to send e-mail
from your cakePHP application
enzoy
Great man.:-)
Thanks,
very helpful.
welcome
i am getting an error saying “Unable to find the socket transport "ssl" – did you forget to enable it when you configured PHP? “
You have to configure in php.ini file for ssl.
Try below link
http://stackoverflow.com/questions/4163273/email-component-cakephp
templet.ctp..why include this?
Hi Rizwan,
That is file where we place content of email we going to send.
that file can be in any name. it can be both in html format or text format.
I think this may help you
It is great way to send mail using smtp .But i found a query in that ,There is no option to send body part excluding template.
Hi,
I think you are asking like this. You can send email without template. See options below.
$this->Email->delivery = ‘smtp’;
$this->Email->from = $this->data["Contact"]["from"];
$this->Email->to = $this->data["Contact"]["to"];
$this->Email->subject = $this->data["Contact"]["subject"];
//$this->Email->template = “default”;
$this->Email->send($this->data["Contact"]["body"]);
I have uncommented template options and passed body text to send() as parameter.
I would like to thank you for the efforts you’ve put in writing this blog. I’m hoping the same high-grade site post from you in the upcoming as well. Actually your creative writing skills has inspired me to get my own site now. Really the blogging is spreading its wings rapidly. Your write up is a good example of it.
my template.ctp isn’t rendering html, also how will I pass values in template
Nice working for me
Hey hi can any one tell me that where we have to call this Email funciton?
Nice work. Quick question, how do I pass form input into template.ctp
Hi victor,
Thank you.
Just set variable using $this->set(compact(‘variable’))
You can be able to use that variable.
“Send Email using smtp in cakePHP | Sathia’s Blog” was indeed a pretty wonderful post, . Keep publishing and I’ll
try to continue to keep reading! Thanks for the post -Autumn