Created
December 31, 2015 21:15
-
-
Save fabiopaiva/8db28da609f6090c9fba to your computer and use it in GitHub Desktop.
ZF2 + SMTP + Gmail
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
{ | |
"require": { | |
"zendframework/zend-mail": "^2.5" | |
} | |
} |
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 | |
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('emaildestinatario@mail.com') | |
->setFrom('emailremetente@mail.com') | |
->setSubject('Zend Mail') | |
->setBody($body); | |
$transport = new Smtp(); | |
$transport->setOptions(new SmtpOptions([ | |
'host' => 'smtp.gmail.com', | |
'port' => 587, | |
'connection_class' => 'plain', | |
'connection_config' => [ | |
'username' => 'emailremetente@mail.com', | |
'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