doudan4834 2013-06-17 09:08
浏览 31
已采纳

发送邮件在我的机器上成功但使用phpmailer使服务器失败

<?php
date_default_timezone_set('America/Toronto');

require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = "gdssdh";
//$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "myemail@gmail.com";  // GMAIL username
$mail->Password   = "******";            // GMAIL password

$mail->SetFrom('mysent@gmail.com', 'PRSPS');

//$mail->AddReplyTo("user2@gmail.com', 'First Last");

$mail->Subject    = "PRSPS password";

//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "mymail@yahoo.co.in";
$mail->AddAddress($address, "user2");

//$mail->AddAttachment("images/phpmailer.gif");      // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

When I run the script on my local machine I got

CLIENT -> SMTP: EHLO localhost CLIENT -> SMTP: AUTH LOGIN CLIENT -> SMTP: cHV0aGVhLmh1b25nMjAxNEBnbWFpbC5jb20= CLIENT -> SMTP: UHV0aGVhMDEy CLIENT -> SMTP: MAIL FROM: CLIENT -> SMTP: RCPT TO: CLIENT -> SMTP: DATA CLIENT -> SMTP: Date: Mon, 17 Jun 2013 04:25:49 -0400 CLIENT -> SMTP: Return-Path: CLIENT -> SMTP: To: user2 CLIENT -> SMTP: From: PRSPS CLIENT -> SMTP: Subject: PRSPS password CLIENT -> SMTP: Message-ID: <405be3508111cd4789653ec34cdfba23@localhost> CLIENT -> SMTP: X-Priority: 3 CLIENT -> SMTP: X-Mailer: PHPMailer 5.2.6 (https://github.com/PHPMailer/PHPMailer/) CLIENT -> SMTP: MIME-Version: 1.0 CLIENT -> SMTP: Content-Type: multipart/alternative; CLIENT -> SMTP: boundary="b1_405be3508111cd4789653ec34cdfba23" CLIENT -> SMTP: Content-Transfer-Encoding: 8bit CLIENT -> SMTP: CLIENT -> SMTP: --b1_405be3508111cd4789653ec34cdfba23 CLIENT -> SMTP: Content-Type: text/plain; charset=iso-8859-1 CLIENT -> SMTP: Content-Transfer-Encoding: 8bit CLIENT -> SMTP: CLIENT -> SMTP: gdssdh CLIENT -> SMTP: CLIENT -> SMTP: CLIENT -> SMTP: --b1_405be3508111cd4789653ec34cdfba23 CLIENT -> SMTP: Content-Type: text/html; charset=iso-8859-1 CLIENT -> SMTP: Content-Transfer-Encoding: 8bit CLIENT -> SMTP: CLIENT -> SMTP: gdssdh CLIENT -> SMTP: CLIENT -> SMTP: CLIENT -> SMTP: CLIENT -> SMTP: --b1_405be3508111cd4789653ec34cdfba23-- CLIENT -> SMTP: CLIENT -> SMTP: . CLIENT -> SMTP: quit Message sent!

But When I run the same script on hosting

SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)SMTP Connect() failed. Mailer Error: SMTP Connect() failed.

Do you have any idea to fix this problem?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doujinge9648 2013-06-17 09:21
    关注

    Your hosting may have firewalled the used ports. Try using other ports (with other security) settings or contact your hoster.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题