Skip to content

Instantly share code, notes, and snippets.

@sungitly
Created March 20, 2014 02:07
Show Gist options
  • Save sungitly/9655852 to your computer and use it in GitHub Desktop.
Save sungitly/9655852 to your computer and use it in GitHub Desktop.
Send Email Through SMTP (SSL) Using Zend
<?php
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
use Zend\Mail\Message;
public function sendEmail($to, $subject, $body){
$message = new Message();
$message->addTo($to)
->addFrom('helpdesk@example.com')
->setSubject($subject)
->setBody($body);
// Setup SMTP transport using PLAIN authentication over TLS
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'example.com',
'host' => 'smtp.example.com',
'port' => 465,
'connection_class' => 'login',
'connection_config' => array(
'username' => 'helpdesk@example.com',
'password' => 'password',
'ssl' => 'ssl',
),
));
$transport->setOptions($options);
$transport->send($message);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment