我想在本地主机中使用php脚本发送邮件。通过google,我找到了switchmailer。我使用swiftmailer尝试了下面的代码。从代理服务器的本地主机发送PHP邮件
<?php
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587)
->setUsername('[email protected]')
->setPassword('gmailpassword')
;
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('[email protected]' => 'John Doe'))
->setTo(array('[email protected]', '[email protected]' => '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 Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Network is unreachable #101]' in /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/StreamBuffer.php:259\nStack trace:\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->initialize(Array)\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_Mailer->send(Object(Swift_Message))\n#4 {main}\n thrown in /home/shashwat001/public_html/swift/lib/classes/Swift/Transport/StreamBuffer.php on line 259
的原因似乎是,我连接到LAN网络,以便后面一个代理服务器。关于switchmailer中的代理设置,网络上没有太多东西。
有什么办法可以在局域网之外的任何地方使用本地主机在代理服务器后面发送邮件吗?
它是什么样的代理? SOCKS? SSH端口转发?乌贼? – 2013-03-04 18:07:07
这是http/https代理 – 2013-03-04 18:08:14
不确定您可以通过端口80隧道smtp。http未精确设置为支持实际连接到远程服务器和“上载”电子邮件所必需的smtp命令序列。 – 2013-03-04 18:10:04