我想在localhost中使用php脚本发送邮件。通过谷歌我找到了switchmailer。我使用swiftmailer尝试了以下代码。
<?php
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587)
->setUsername('gmailid@gmail.com')
->setPassword('gmailpassword')
;
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john@doe.com' => 'John Doe'))
->setTo(array('mail1@gmail.com', 'mail2@gmail.com' => 'A name'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
?>
代码在激烈的行$result = $mailer->send($message);
php错误日志文件包含以下信息
[error] [client 127.0.0.1] PHP致命错误:未捕获异常 'Swift_TransportException',消息'连接不能 与主机smtp.gmail.com建立[网络无法访问#101]' /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/StreamBuffer.php:259\nStack 追踪:\ n#0 /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/StreamBuffer.php(64): Swift_Transport_StreamBuffer-&GT; _establishSocketConnection()\ n#1 /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer-&GT;初始化(阵列)\ N#2 /home/shashwat001/public_html/swift/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport-&GT;启动()\ N#3 /home/shashwat001/public_html/swift/index.php(31): Swift_Mailer-&gt;发送(Object(Swift_Message))\ n#4 {main} \ n抛出 /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/StreamBuffer.php 在第259行
原因似乎是我连接到LAN网络,所以在代理服务器后面。关于switchmailer中的代理设置,网上没有什么内容。
有没有办法使用localhost在代理服务器后面的任何地方发送邮件?
答案 0 :(得分:1)
Google Mail的正确端口为465,Google也使用SSL连接Gmail。