更新:我已经设法找到问题的解决方案,早些时候问道。一切似乎都有效,没有显示错误,但我没有收到电子邮件
端口465已打开,我可以远程登录。 根据我在stackoverflow上找到的建议,我尝试检查SMTP服务器日志记录,但在安装IIS以启用日志记录后,我的Apache服务器停止工作 - >我试图改变端口,但它没有帮助。我被卡住了......
<?php
require 'PHPmailer\class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Port = 465;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'test@gmail.com';
$mail->Password = 'test';
$mail->SMTPSecure = 'ssl';
if (!empty($_GET)){
$errors=array();
$email = isset($_GET['email']) ? $_GET['email'] : '';
$name = isset($_GET['name']) ? $_GET['name'] : '';
$message = isset($_GET['message']) ? $_GET['message'] : '';
if (empty($name) || empty($email) || empty($message)){
$errors[]='All fields are required!';
}else{
if (!filter_var("$email", FILTER_VALIDATE_EMAIL)){
$errors[]='The email is not valid!';
}
}
if (empty($errors)){
$mail->From = $email;
$mail->FromName = $name;
$mail->IsHTML(true);
$mail->Body = $message;
$mail->Subject ="From IMDB";
$mail->IsHTML(true);
$result = $mail->Send();
if(!$result) {
echo $mail->ErrorInfo;
} else {
header('Location:contactForm.php?sent');
exit();
}
}
}
?>
我也会附上一些php.ini:
smtp_port = 465;
auth_username = test@gmail.com
auth_password = test
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
感谢您的帮助