Created
December 31, 2015 21:15
-
-
Save fabio-paiva-sp/8db28da609f6090c9fba to your computer and use it in GitHub Desktop.
ZF2 + SMTP + Gmail
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
{ | |
"require": { | |
"zendframework/zend-mail": "^2.5" | |
} | |
} |
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
<?php | |
require 'vendor/autoload.php'; | |
use Zend\Mail\Transport\Smtp; | |
use Zend\Mail\Transport\SmtpOptions; | |
use Zend\Mail\Message; | |
use Zend\Mime\Message as MimeMessage; | |
use Zend\Mime\Part as MimePart; | |
$message = new Message(); | |
$body = new MimeMessage(); | |
$html = 'Mensagem teste'; | |
$htmlPart = new MimePart($html); | |
$htmlPart->setType('text/html'); | |
$body->setParts(array($htmlPart)); | |
$message->setEncoding('utf-8') | |
->addTo('[email protected]') | |
->setFrom('[email protected]') | |
->setSubject('Zend Mail') | |
->setBody($body); | |
$transport = new Smtp(); | |
$transport->setOptions(new SmtpOptions([ | |
'host' => 'smtp.gmail.com', | |
'port' => 587, | |
'connection_class' => 'plain', | |
'connection_config' => [ | |
'username' => '[email protected]', | |
'password' => 'senha', | |
'ssl' => 'tls', | |
] | |
])); | |
$transport->send($message); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment