Created
October 31, 2012 17:57
-
-
Save samsonasik/3988701 to your computer and use it in GitHub Desktop.
Send HTML Mail Using ZF2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('[email protected]') | |
->addFrom('[email protected]') | |
->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
Yup itz working...simplest method to add html content and send mail....Big thankyou