Thursday, 6 June 2019

How to send email from zend framework 3?

How to send email from zend framework 3?
define('MR_MAIL_HOST','smtp.sendgrid.net');
define('MR_MAIL_PORT','587');
define('MR_MAIL_USERNAME','username');  
define('MR_MAIL_PASSWORD','password');  

$transport = new Mail\Transport\Smtp();
$options   = new Mail\Transport\SmtpOptions(array(
    'name'              => 'emailName',
    'host'              => MR_MAIL_HOST,
    'connection_class'  => 'login',
    'connection_config' => array(
        'username' => (MR_MAIL_USERNAME),
        'password' => (MR_MAIL_PASSWORD),
         'port' => MR_MAIL_PORT,
    ),
));
$transport->setOptions($options);

$mail = new Mail\Message();
$mail->setFrom('hello@domain.com');
$mail->setSubject('This is simple subject');
$mail->setBody('this is html body text');
$mail->addTo('arun@www.web-technology-experts-notes.in');
$transport->send($mail);