Coding Cheatsheets - Learn web development code and tutorials for Software developers which will helps you in project. Get help on JavaScript, PHP, XML, and more.

Post Page Advertisement [Top]

Basic usage
First of all, you should ensure the class is loaded using App::uses():

App::uses('CakeEmail', 'Network/Email');
Using CakeEmail is similar to using EmailComponent. But instead of using attributes you use methods. Example:

$Email = new CakeEmail();
$Email->from(array('me@example.com' => 'My Site'));
$Email->to('you@example.com');
$Email->subject('About');
$Email->send('My message');

To enable the transport, add the following information to your Config/email.php:

You can configure SSL SMTP servers such as Gmail. To do so, prefix the host with 'ssl://' and configure the port value accordingly. Example:

class EmailConfig {
    public $gmail = array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'my@gmail.com',
        'password' => 'secret',
        'transport' => 'Smtp'
    );
}

public $smtp = array(
'transport' => 'Smtp',
//'from' => array('site@localhost' => 'My Site'),
'host' => 'smtp.mailgun.org',
'port'=>'587',
'timeout' => 30,
'mailgun_domain'    => 'my-mailgun-domain.com',
'username'=>'username',
'password'=>'password',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);

$email = new CakeEmail('smtp');

No comments:

Post a Comment

Bottom Ad [Post Page]