php - PHPmailer不向gmail发送消息
问题描述
我正在尝试从我的网站 specialeducationnotes.co.in 发送消息,但无法发送消息。
<?php
if(isset($_POST['query-submit'])) {
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
// $mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myemail@gmail.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$from = $_POST['email'];
$subject = $_POST['subject'];
$mail->From = $from;
$mail->FromName = $_POST['name'];
$mail->addAddress('specialeducationnotes1@gmail.com'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = '<h2 style="text-align: center;"s>Name: '.$_POST['name'].'<br>Email: '.$_POST['email'].'<br>Message: '.$_POST['query'].'</h2>';
$mail->AltBody = 'Hello! Hola! Namaste!';
if(!$mail->send()) {
//echo 'Message could not be sent.';
echo "<script>alert(' Your message could not be sent!');</script>";
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
//echo 'Message has been sent';
echo "<script>alert(' Your message is sent!');</script>";
echo "<script>document.location.href='index.php'</script>";
}
}
?>
我只是得到一个没有错误消息或任何文本和电子邮件的空白页也没有发送。你能告诉我的代码有什么问题吗?
解决方案
推荐阅读
- javascript - 如何从表中读取sql数据并在nodejs中生成变量?
- android - android:mutablelivedata 更改不会更新 UI
- ruby-on-rails - ActiveRecord find_by 生成不适用于 postgres 的 select 语句
- sql-server - 是否可以检索完整的行数以及返回部分结果
- android - 如何在片段中使用滑动面板
- c# - 为什么我的球员统一轮换
- c# - C# pinvoke - 类派生
- c++ - 在 GCC 8 上工作的 Consexpr 计数器,不限于命名空间范围
- angular - 为什么我的 Angular 6 按钮没有波纹?
- python - 如何在python中将excel文件转换为这种格式?