Skip to content

Instantly share code, notes, and snippets.

@fwahlqvist
Forked from samsonasik/gist:3988701
Created November 29, 2012 22:56
Show Gist options
  • Save fwahlqvist/4172473 to your computer and use it in GitHub Desktop.
Save fwahlqvist/4172473 to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment