Problem
How do I set up outbound SMTP using CakePHP?
How do I set up outbound SMTP using the email component from CakePHP?
How do I use outMail in CakePHP?
How do I use outMail with the email component from CakePHP?
Solution
The following example of code assumes you have already got a fully functional webserver and the CakePHP framework installed and working.
Example code outmail-cakephp.php
<?php
public $default = array(
'host' => 'mxXXXXXX.smtp-engine.com',
'port' => 25,
'auth' => 'plain',
'username' => 'outmail_username',
'password' => '**********',
'tsl' => false,
'transport' => 'smtp',
'from' => array('me@example.com' => 'Username'),
'returnPath' => 'me@example.com',
'layout' => false,
'emailFormat' => 'html',
'template' => 'only_text',
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
$this->Email->to = 'Name <toaddress@example.com>';
$this->Email->subject = 'Subject goes here...';
$this->Email->from = 'My Name <me@xample.com>';
$this->Email->template = 'user_confirm';
$this->Email->sendAs = 'html';
$this->Email->smtpOptions = $default;
$this->Email->delivery = 'smtp';
if ($this->Email->send()) {
return true;
} else {
echo $this->Email->smtpError;
}
?>
Summary of server details
Outgoing server |
mxXXXXXX.smtp-engine.com As provided in your signup email. |
Outgoing server protocol |
SMTP |
Outgoing server port |
25, 465, 587, 2525 or 8025 |
Authentication Type |
Basic Authentication, SSL and TLS supported |
Username |
As provided |
Password |
As provided |