首页 > 解决方案 > 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>";
            }
        }
?>

我只是得到一个没有错误消息或任何文本和电子邮件的空白页也没有发送。你能告诉我的代码有什么问题吗?

标签: phpphpmailer

解决方案


推荐阅读