Created
March 20, 2014 02:07
-
-
Save sungitly/9655852 to your computer and use it in GitHub Desktop.
Send Email Through SMTP (SSL) Using Zend
This file contains 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
<?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