我有整合Sendgrid使用STMP API我的Zend Framework 2应用程序,我已经使用Zend的交通运输的,但我得到一个错误Sendgrid未验证发件人不允许错误的PHP,ZF2
“捕获的异常:无法从指定的地址收到:未经身份验证的发件人不允许”
$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;
}
}