Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Send HTML Mail Using ZF2
use Zend\Mail\Message;
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mime\Message as MimeMessage;
use Zend\Mime\Part as MimePart;
use Zend\Mail\Transport\SmtpOptions;
//////////
$message = new Message();
$message->addTo('samsonasik@yahoo.com')
->addFrom('samsonasik@gmail.com')
->setSubject('Test send mail using ZF2');
// Setup SMTP transport using LOGIN authentication
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'host' => 'smtp.gmail.com',
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => 'yourgmailusername',
'password' => 'yourgmailpassword'
),
'port' => 587,
));
$html = new MimePart('<b>heii, <i>sorry</i>, i\'m going late</b>');
$html->type = "text/html";
$body = new MimeMessage();
$body->addPart($html);
$message->setBody($body);
$transport->setOptions($options);
$transport->send($message);
@vluis

This comment has been minimized.

Copy link

@vluis vluis commented Jun 5, 2014

I have the following problem zendframework/zendframework#5708 (comment)
please I await your response, thanks.
👍

@rajeshmandal81

This comment has been minimized.

Copy link

@rajeshmandal81 rajeshmandal81 commented Jun 29, 2014

Hey plz upload how to send mail using Yahoo account

@erpriyanka

This comment has been minimized.

Copy link

@erpriyanka erpriyanka commented May 23, 2016

Yup itz working...simplest method to add html content and send mail....Big thankyou

@neutronixx

This comment has been minimized.

Copy link

@neutronixx neutronixx commented Jul 4, 2018

Works! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment