Reputation: 536
I have integrate Sendgrid for my Zend Framework 2 Application using STMP API and i have used Zend Transport for but I get a error
"Caught exception: Cannot receive from specified address : Unauthenticated senders not allowed"
$request = $this->getRequest();
//$form = new Add();
// $product = new Product();
$username = 'XXX';
$password ='XXXX';
if ($request->isXmlHttpRequest()){ // If it's ajax call
$email = $request->getPost('email_add');
$message = $request->getPost('message');
try{
$message = new Message();
$message->addTo('[email protected]')
->addFrom('[email protected]')
->setSubject('Greetings and Salutations!')
->setBody("Sorry, I'm going to be late today!");
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'sendgrid.com',
'host' => 'smtp.sendgrid.net',
'port' => 587, // Notice port change for TLS is 587
'connection_class' => 'smtp',
'connection_config' => array(
'auth' => 'login',
'username' => 'XXXXXX',
'password' => 'XXXXXX',
'ssl' => 'tls'
),
));
$transport->setOptions($options);
$transport->send($message);
exit;
}catch (\Exception $ex){
echo 'Caught exception: ', $ex->getMessage(), "\n";
exit;
}
}
Upvotes: 0
Views: 1179
Reputation: 2653
Try this
connection_class plain should work
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => $name,
'host' => $host,
'port' => 587,
'connection_class' => 'plain',
'connection_config' => array(
'username' => $username,
'password' => $password,
),
));
$transport->setOptions($options);
$transport->send($mail);
Upvotes: 0
Reputation: 2228
In addition to using the SimMail option, you can try using Zend's mail module as described in our documentation: http://sendgrid.com/docs/Integrate/Frameworks/zend.html
One other option is our Web API, for which we have a PHP library here: https://github.com/sendgrid/sendgrid-php
Upvotes: 0
Reputation: 13558
Sendgrid has an api and this api is implemented by SlmMail (disclaimer: I am the author of SlmMail). Using that API is easier to use than using the old SMTP protocol.
I am not sure how to exactly configure the SMTP options, but previously we worked with the Google SMTP servers and it required this configuration:
'name' => 'gmail.com',
'host' => 'smtp.gmail.com',
'port' => 587,
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => $username,
'password' => $password,
),
This is slightly different than yours ("class" is "login", there is no "auth" option). Check also the documentation where all SMTP options are specified.
Upvotes: 1