sent mail succed on my machine but failed the server using phpmailer

巧了我就是萌 提交于 2019-12-12 01:06:48

问题


<?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:


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



来源:https://stackoverflow.com/questions/17143986/sent-mail-succed-on-my-machine-but-failed-the-server-using-phpmailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!