phpmailer发送gmail smtp超时

phpmailer发送gmail smtp超时,php,smtp,phpmailer,Php,Smtp,Phpmailer,可能重复: 有很多类似的问题,但没有一个对我有帮助 以下是phpmailer exmaples中提供的我的脚本: require_once('../class.phpmailer.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(true); // the true pa

可能重复:

有很多类似的问题,但没有一个对我有帮助

以下是phpmailer exmaples中提供的我的脚本:

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

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP

try {
  $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  $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   = "yourusername@gmail.com";  // GMAIL username
  $mail->Password   = "yourpassword";            // GMAIL password
  $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
  $mail->SetFrom('name@yourdomain.com', 'First Last');
  $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  $mail->MsgHTML("some message");
  $mail->Send();
  echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}  
在许多问题中,提到了启用在我的服务器中启用的
php\u openssl extension
。我正在使用PHPmailer版本5.1

我的服务器端口25也没有问题,简单的
mail()
功能工作正常


感谢您的帮助

以下是一个工作示例:

  require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
  $Mail = new PHPMailer();
  $Mail->IsSMTP(); // Use SMTP
  $Mail->Host        = "smtp.gmail.com"; // Sets SMTP server
  $Mail->SMTPDebug   = 2; // 2 to enable SMTP debug information
  $Mail->SMTPAuth    = TRUE; // enable SMTP authentication
  $Mail->SMTPSecure  = "tls"; //Secure conection
  $Mail->Port        = 587; // set the SMTP port
  $Mail->Username    = 'MyGmail@gmail.com'; // SMTP account username
  $Mail->Password    = 'MyGmailPassword'; // SMTP account password
  $Mail->Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
  $Mail->CharSet     = 'UTF-8';
  $Mail->Encoding    = '8bit';
  $Mail->Subject     = 'Test Email Using Gmail';
  $Mail->ContentType = 'text/html; charset=utf-8\r\n';
  $Mail->From        = 'MyGmail@gmail.com';
  $Mail->FromName    = 'GMail Test';
  $Mail->WordWrap    = 900; // RFC 2822 Compliant for Max 998 characters per line

  $Mail->AddAddress( $ToEmail ); // To:
  $Mail->isHTML( TRUE );
  $Mail->Body    = $MessageHTML;
  $Mail->AltBody = $MessageTEXT;
  $Mail->Send();
  $Mail->SmtpClose();

  if ( $Mail->IsError() ) { 
    echo "ERROR<br /><br />";
  }
  else {
    echo "OK<br /><br />";
  }
require_once('class.phpmailer.php');//根据需要添加路径
$Mail=new PHPMailer();
$Mail->IsSMTP();//使用SMTP
$Mail->Host=“smtp.gmail.com”;//设置SMTP服务器
$Mail->SMTPDebug=2;//2以启用SMTP调试信息
$Mail->SMTPAuth=TRUE;//启用SMTP身份验证
$Mail->SMTPSecure=“tls”//安全连接
$Mail->Port=587;//设置SMTP端口
$Mail->Username=MyGmail@gmail.com'; // SMTP帐户用户名
$Mail->Password='MyGmailPassword';//SMTP帐户密码
$Mail->Priority=1;//最高优先级-电子邮件优先级(1=高,3=正常,5=低)
$Mail->CharSet='UTF-8';
$Mail->Encoding='8bit';
$Mail->Subject='使用Gmail测试电子邮件';
$Mail->ContentType='text/html;字符集=utf-8\r\n';
$Mail->FromMyGmail@gmail.com';
$Mail->FromName='gmailtest';
$Mail->WordWrap=900;//符合RFC 2822,每行最多998个字符
$Mail->AddAddress($ToEmail);//致:
$Mail->isHTML(TRUE);
$Mail->Body=$MessageHTML;
$Mail->AltBody=$MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
如果($Mail->IsError()){
回显“错误

”; } 否则{ 回显“OK

”; }
ping来自同一服务器的主机\端口(如果是网络)issue@Dagon:ping没有问题。我也在localhost上尝试过,但也存在同样的问题。几个月前,我用这种方法发了很多电子邮件,效果很好,但现在我忘了如何…效果很好!谢谢但是,有没有同样的解决方案来使用yahoo帐户发送邮件?只需修改SMTP参数即可。我不认识他们,但你可以在雅虎找到他们。
  require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
  $Mail = new PHPMailer();
  $Mail->IsSMTP(); // Use SMTP
  $Mail->Host        = "smtp.gmail.com"; // Sets SMTP server
  $Mail->SMTPDebug   = 2; // 2 to enable SMTP debug information
  $Mail->SMTPAuth    = TRUE; // enable SMTP authentication
  $Mail->SMTPSecure  = "tls"; //Secure conection
  $Mail->Port        = 587; // set the SMTP port
  $Mail->Username    = 'MyGmail@gmail.com'; // SMTP account username
  $Mail->Password    = 'MyGmailPassword'; // SMTP account password
  $Mail->Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
  $Mail->CharSet     = 'UTF-8';
  $Mail->Encoding    = '8bit';
  $Mail->Subject     = 'Test Email Using Gmail';
  $Mail->ContentType = 'text/html; charset=utf-8\r\n';
  $Mail->From        = 'MyGmail@gmail.com';
  $Mail->FromName    = 'GMail Test';
  $Mail->WordWrap    = 900; // RFC 2822 Compliant for Max 998 characters per line

  $Mail->AddAddress( $ToEmail ); // To:
  $Mail->isHTML( TRUE );
  $Mail->Body    = $MessageHTML;
  $Mail->AltBody = $MessageTEXT;
  $Mail->Send();
  $Mail->SmtpClose();

  if ( $Mail->IsError() ) { 
    echo "ERROR<br /><br />";
  }
  else {
    echo "OK<br /><br />";
  }