【问题标题】:SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP hostSMTP 错误:无法连接到 SMTP 主机。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机
【发布时间】:2015-10-20 07:57:43
【问题描述】:

大家好,我是 php 和 html 的新手,面临的问题: SMTP 错误:无法连接到 SMTP 主机。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。但在本地 xampp 中工作正常并且在服务器中出现错误。 代码如下:

<?php
    $name = $_POST['name'];
    $contact = $_POST['contact'];
    $email = $_POST['email'];
    $company = $_POST['company'];
    $message = $_POST['message'];
    $msg= " <strong>Name:</strong> $name <br /> <strong>Contact:</strong> $contact <br /> <strong>Email:</strong> $email <br /><strong>Company:</strong> $company <br /><strong>Message:</strong> $message";
    require_once('mailer/class.phpmailer.php');
    $mail             = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host       = "smtp.gmail.com";
    $mail->SMTPDebug  = 0;               
    $mail->SMTPSecure = "ssl";
    $mail->SMTPAuth   = true;                  
    $mail->Host       = "smtp.gmail.com";
    $mail->Port       = 465;                    
    //$mail->Username   = "me@domain.com";
    //$mail->Password   = "gmail pass";    
    //$mail->SetFrom('balajeeenterprises9@gmail.com', 'Pankaj U');
    $mail->SetFrom($email);
    $mail->AddReplyTo($email);
    $mail->Subject    = "Enquiry from Website";
    $mail->MsgHTML($msg);
    $address = "balajeeenterprises9@gmail.com";
    $mail->AddAddress($address, $name);
    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      header('Location: thanks.html');
    }
?>

【问题讨论】:

  • 你需要检查你的防火墙
  • 但在本地服务器上工作正常?

标签: php smtp


【解决方案1】:
$mail->SMTPSecure = "tls";
$mail->Port       = 587; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多