Zend framework2 Zend\Mail\Message问题
我正在使用ZF2的消息类尝试发送电子邮件。但是,在执行下面的代码后,页面尝试重定向,大约一分钟后,我收到一个“本地主机已超时”错误。有什么想法吗Zend framework2 Zend\Mail\Message问题,zend-framework2,Zend Framework2,我正在使用ZF2的消息类尝试发送电子邮件。但是,在执行下面的代码后,页面尝试重定向,大约一分钟后,我收到一个“本地主机已超时”错误。有什么想法吗 $message = new Message(); $message->addTo('ToEmail@gmail.com') ->addFrom('FromEmail@gmail.com') ->setSubject('Greetings and Salutations!') -&g
$message = new Message();
$message->addTo('ToEmail@gmail.com')
->addFrom('FromEmail@gmail.com')
->setSubject('Greetings and Salutations!')
->setBody("Sorry, I'm going to be late today!");
// Setup SMTP transport using LOGIN authentication
// Setup SMTP transport using PLAIN authentication over TLS
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => 'localhost',
'host' => 'localhost',
'port' => 8888, // Notice port change for TLS is 587
'connection_class' => 'plain',
'connection_config' => array(
'username' => 'FromEmail@gmail.com',
'password' => 'FromPassword',
'ssl' => 'tls',
),
));
$transport->setOptions($options);
$transport->send($message);
我能够使用Zend Framework 2.0发送电子邮件。请遵循以下代码集
$options = new Mail\Transport\SmtpOptions(
'smtp_options' => array(
'name' => 'localhost',
'host' => 'smtp.gmail.com',
'port'=> 587,
'connection_class' => 'login',
'connection_config' => array(
'username' => '<your gmail account username>@gmail.com',
'password' => '<your gmail account password>',
'ssl' => 'tls'
),
)
);
$content = 'Message to be sent in the email.(goes here)';
// make a header as html
$html = new MimePart($content);
$html->type = "text/html";
$body = new MimeMessage();
$body->setParts(array($html));
// instance mail
$mail = new Mail\Message();
$mail->setBody($body); // will generate our code html from template.phtml
$mail->setFrom('FromEmail@gmail.com');
$mail->setTo('ToEmail@gmail.com');
$mail->setSubject('Subject for sending email.');
$transport = new Mail\Transport\Smtp($options);
$transport->send($mail);
$options=new Mail\Transport\SmtpOptions(
“smtp_选项”=>数组(
“名称”=>“本地主机”,
'host'=>'smtp.gmail.com',
“端口”=>587,
'连接\u类'=>'登录',
“连接配置”=>数组(
“用户名”=>“@gmail.com”,
'密码'=>'',
“ssl”=>“tls”
),
)
);
$content='要在电子邮件中发送的消息(转到此处)';
//将标题设置为html
$html=新的MimePart($content);
$html->type=“text/html”;
$body=new mimessage();
$body->setParts(数组($html));
//实例邮件
$mail=新邮件\消息();
$mail->setBody($body);//将从template.phtml生成我们的html代码
$mail->setFrom('FromEmail@gmail.com');
$mail->setTo('ToEmail@gmail.com');
$mail->setSubject('发送电子邮件的主题');
$transport=new Mail\transport\Smtp($options);
$transport->send($mail);
如果你在工作中遇到任何问题,请告诉我dineshs@mindfiresolutions.com我只是好奇,但根据您的设置,您是否能够telnet localhost 8888并获得响应?正常的SMTP设置是端口25或587(TLS)。是的,我可以telnet到8888。我尝试了25和587,但它无法连接。我还尝试再次执行代码,但没有收到“本地主机超时”错误,而是收到以下“错误324(net::ERR_EMPTY_RESPONSE):服务器关闭了连接,但没有发送任何数据。”因为您正在使用SMTP,你能试着在你的桌面邮件客户端上使用该服务器作为发送邮件服务器,看看从那里发送邮件是否有效吗?我在Mac上,所以我配置了邮件应用程序来发送邮件,但不知道如何查看邮件是否真的发送了。因此,我使用终端运行以下操作:mail-s“Testing”
whoami
@hostname
。它似乎具有相同的功能。使用它,我可以收发邮件。