doujiao3998 2018-11-01 07:05
浏览 2909

SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/托管时的故障排除

While running the PHPMailer in localhost mail will be sending but while hosting the PHPMailer shows the error as SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting. please help me.

here is my code

 <?php
//include PHPMailerAutoload.php
require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer();

$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'mail@gmail.com';
$mail->Password = 'password';

$mail->setFrom('mail@gmail.com', 'mail');
$mail->addAddress('mail@gmail.com');
$mail->Subject = 'SMTP email test';
$mail->Body = 'Thanks for commenting';


if ($mail->send())
    echo "mail is sent";
else
    echo $mail->ErrorInfo;
?>
  • 写回答

1条回答 默认 最新

  • dongwei7913 2018-11-01 10:25
    关注

    Ok let's make it clearly :

    • Make sure your SMTP Port code is same with SMPT port in your host
    • Auth to your account is not wrong
    • Check phpmailer class are success to call like vardump or something else

    Sample of my Code :

      require(https://example.com/PHPMailerAutoload.php');
      require(https://example.com/class.phpmailer.php');
      $mail = new PHPMailer();
      $mail->IsSMTP();
      $mail->Host = 'mail.example.com';
      $mail->SMTPAuth = TRUE;
    
      $mail->Username = 'customer_service@example.com'; 
      $mail->Password = 'blablabla'; 
    
      $mail->From = 'customer_service@example.com';
      $mail->setFrom('customer_service@example.com', 'My Cool Website');
    
      $mail->AddAddress('recipient@destination.com', 'Recipient Full Name');
      $mail->WordWrap = 70;
    
      $mail->Subject = 'PHP Mailer';
      $mail->Body = 'Awesome';
    
      $mail->IsHTML(TRUE);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?