首页 文章

从代理服务器后面的localhost发送PHP邮件

提问于
浏览
2

我想在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错误日志文件包含以下信息

[错误] [客户端127.0.0.1] PHP致命错误:/ home / shashwat001 / public_html /中未显示异常'Swift_TransportException',消息'无法与主机smtp.gmail.com [网络无法访问#101] Build 连接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-> 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 \ n在第259行的/home/shashwat001/public_html/swift/lib/classes/Swift/Transport/StreamBuffer.php中引发

原因似乎是我连接到LAN网络,所以在代理服务器后面 . 关于switchmailer中的代理设置,网上没有什么内容 .

有没有办法使用localhost在代理服务器后面的任何地方发送邮件?

1 回答

  • 1

    Google Mail的正确端口为465,Google也使用SSL连接Gmail .

相关问题