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);
    
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码