Skip to content

Instantly share code, notes, and snippets.

@fabiopaiva
Created December 31, 2015 21:15
Show Gist options
  • Save fabiopaiva/8db28da609f6090c9fba to your computer and use it in GitHub Desktop.
Save fabiopaiva/8db28da609f6090c9fba to your computer and use it in GitHub Desktop.
ZF2 + SMTP + Gmail
{
"require": {
"zendframework/zend-mail": "^2.5"
}
}
<?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