php - 无法让 PHP 邮件程序与 Gmail 帐户一起使用
问题描述
我正在为我的网站使用网络托管,但我无法让联系表正常工作。出于某种原因,每当我在电子邮件标签中使用 gmail 地址时,都会显示以下错误:“您的邮件无法发送!PHPMailer 错误:无法实例化邮件功能。”
联系表格接受任何其他电子邮件域。
这是我正在使用的 php 代码:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$myEmail = 'company@email.com';
$myPassword = 'password';
$myPersonalEmail = 'myemail@gmail.com';
require './PHPMailer/src/Exception.php';
require './PHPMailer/src/PHPMailer.php';
require './PHPMailer/src/SMTP.php';
if(isset($_POST['submit'])) {
$mail = new PHPMailer(true);
$mail->SMTPDebug = 0;
$mail->Host = 'mail.domain.com';
$mail->SMTPAuth = true;
$mail->Username = $myEmail;
$mail->Password = $myEmailPassword;
$mail->SMTPSecure = 'tls';
$mail->Port = 465;
$mail->setFrom($myEmail, 'Company name');
$mail->addAddress($myPersonalEmail);
$mail->addReplyTo($_POST['email'], $_POST['name']);
$mail->isHTML(true);
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['message'];
try {
$mail->send();
header("Location:this_place.html");
echo 'Your message was sent successfully!';
} catch (Exception $e) {
echo "Your message could not be sent! PHPMailer Error: {$mail->ErrorInfo}";
}
} else {
echo "There is a problem with the contact.html document!";
}
?>
我已经看到了许多适用于 SMTP 的解决方案,但我不知道如何将其添加到 PHP 文件中。如果有人能以我的方式发送帮助,我将不胜感激!
解决方案
推荐阅读
- python-3.x - 具有多处理功能的 Python Selenium 在 chrome.exe 进程中导致内存失控
- azure - 关于隔离两个用户在 Azure 中订阅创建的资源
- vhdl - Quartus Prime Lite 找不到实例
- postgresql - 如何在 Ubuntu 上更改 postgresql 版本?
- python - 如何打印使用消息迭代的每个数据帧的行?
- c++ - 替换 std::greater 等
- docusignapi - 将 RSA 私钥转换为字节数组
- python - 使用 pychrome 进行跟踪
- json - 使用powershell将带有列和行的Json转换为csv
- github-actions - 什么是 github 操作相当于 circle ci 的 add_ssh_keys