php - SMTP 错误 : Could not connect to SMTP host. 邮件程序错误:SMTP 错误:无法连接到 SMTP 主机

标签 php smtp

大家好,我是 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');
    }
?>

最佳答案

$mail->SMTPSecure = "tls";
$mail->Port       = 587; 

关于php - SMTP 错误 : Could not connect to SMTP host. 邮件程序错误:SMTP 错误:无法连接到 SMTP 主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33231079/

相关文章:

php - jQuery ajax 和 append - 内容太大?

php - 图像无法显示,因为它包含错误

delphi - 如何将 SMTP Amazon SES 与 Delphi 结合使用?

c# - 使用 Gmail 通过 C# 发送电子邮件

email - 如何使用 Rebol 的 SEND 功能将地址添加到 BCC 字段?

php - 教义和复合唯一键

php - 为什么 shell_exec 对某些命令不起作用/不输出?

java - 从虚假帐户发送电子邮件

ubuntu - Jenkins 失业后发送的电子邮件?

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP