在代理服务器后面从localhost发送PHP邮件
我想在localhost中使用php脚本发送邮件。通过谷歌我找到了switchmailer。我使用swiftmailer尝试了以下代码在代理服务器后面从localhost发送PHP邮件,php,email,localhost,Php,Email,Localhost,我想在localhost中使用php脚本发送邮件。通过谷歌我找到了switchmailer。我使用swiftmailer尝试了以下代码 <?php require_once 'lib/swift_required.php'; $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587) ->setUsername('gmailid@gmail.com') ->setPassword('gmai
<?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);
?>
代码在lase行$result=$mailer->send($message)中出现错误代码>
php错误日志文件包含以下信息
[错误][client 127.0.0.1]PHP致命错误:未捕获异常
带有消息“无法连接”的“Swift_TransportException”
已通过主机smtp.gmail.com[网络无法访问#101]'在中建立
/home/shashwat001/public_html/swift/lib/classes/swift/Transport/StreamBuffer.php:259\n堆栈
跟踪:\n#0
/home/shashwat001/public_html/swift/lib/classes/swift/Transport/StreamBuffer.php(64):
Swift_Transport_StreamBuffer->_establishSocketConnection()\n#1
/home/shashwat001/public_html/swift/lib/classes/swift/Transport/AbstractSmtpTransport.php(115):
Swift_Transport_StreamBuffer->初始化(数组)\n\2
/home/shashwat001/public_html/swift/lib/classes/swift/Mailer.php(80):
Swift_Transport_AbstractSmtpTransport->start()\n#3
/home/shashwat001/public_html/swift/index.php(31):
Swift#U Mailer->send(对象(Swift#U消息))\n#4{main}\n抛出
/home/shashwat001/public_html/swift/lib/classes/swift/Transport/StreamBuffer.php
第259行
原因似乎是我连接到一个局域网,所以在代理服务器后面。关于switchmailer中的代理设置,网络上没有太多内容
有没有办法在代理服务器后面使用localhost在LAN之外的任何地方发送邮件 谷歌邮件的正确端口是465,谷歌也使用SSL连接到Gmail。它是什么类型的代理?袜子SSH端口转发?SQUID?它是http/https代理,不确定是否可以通过端口80对smtp进行隧道传输。http没有完全设置为支持实际连接到远程服务器并“上载”电子邮件所需的smtp命令序列。使用端口465时出现相同的php错误。我认为可以建立smtp连接,除非我在某个我找不到的地方定义了代理设置。您应该在newInstance函数中将第三个参数更改为“ssl”。