Skip to content

Instantly share code, notes, and snippets.

@samsonasik
Created October 31, 2012 17:57
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save samsonasik/3988701 to your computer and use it in GitHub Desktop.
Save samsonasik/3988701 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);
@vluis
Copy link

vluis commented Jun 5, 2014

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

@rajeshmandal81
Copy link

Hey plz upload how to send mail using Yahoo account

@PriyankaSawant26
Copy link

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

@neutronixx
Copy link

Works! Thank you!

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