CakePHP
CakePHP comes with an email library that already supports SMTP. For more information check out the CakePHP documentation page. This example shows how to send an email with both HTML and text bodies.
In app/views/layouts/ you need to define the layout of your text and HTML emails:
1
2
3
4
5
email/
html/
default.ctp
text/
default.ctp1
<!--?php echo $content_for_layout; ?-->
1
<!--?php echo $content_for_layout; ?-->
1
2
3
4
5
6
7
8
app/
views/
elements/
email/
text/
registration.ctp
html/
registration.ctp1
2
Dear <!--?php echo $name ?-->,
Thank you for registering. Please go to http://domain.com to finish your registration.
1
2
Dear <!--?php echo $name ?-->,
Thank you for registering. Please go to <a href="http://domain.com">here</a> to finish your registration.
1
<!--?php var $components = array('Email'); ?-->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
$this->Email->smtpOptions = array(
'port'=>'587',
'timeout'=>'30',
'host' => 'smtp.sendgrid.net',
'username'=>'sendgrid_username',
'password'=>'sendgrid_password',
'client' => 'yourdomain.com'
);
$this->Email->delivery = 'smtp';
$this->Email->from = 'Your Name ';
$this->Email->to = 'Recipient Name ';
$this->set('name', 'Recipient Name');
$this->Email->subject = 'This is a subject';
$this->Email->template = 'registration';
$this->Email->sendAs = 'both';
$this->Email->send();
?>