gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 00:58:53 32 4
gpt4 key购买 nike

大家好,我是 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com