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 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题