简体   繁体   English

我无法使用PHPMailer发送邮件

[英]I am unable to send mail with PHPMailer

This is my index.php file 这是我的index.php文件

Please suggest what is wrong with the below code that i am not receiving mails or if there is any other easy way of sending emails. 请建议以下代码出了什么问题,我没有收到邮件,或者还有其他简单的发送电子邮件的方法。

<?php

$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth=false;
$mail->SMTPSecure='tls';
$mail->Host='smtp.gmail.com';
$mail->port='587';
$mail->isHTML();
$mail->Username='demoXXXXX@gmail.com';
$mail->Password='XXXXXX';
$mail->SetFrom('no-reply@gmail.com');


$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";


$mail->addAddress("parkingston@gmail.com");

if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}

?>     

Include class.phpmailer.php & classes/class.smtp.php first . 首先包含class.phpmailer.php和classes / class.smtp.php。

 <?php
    require "autoload.php";
    include "class.phpmailer.php"; // include the class name
    include "class.smtp.php";

    $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->SMTPAuth=false;
    $mail->SMTPSecure='tls';
    $mail->Host='smtp.gmail.com';
    $mail->port='587';
    $mail->isHTML();
    $mail->Username='demoXXXXX@gmail.com';
    $mail->Password='XXXXXX';
    $mail->SetFrom('no-reply@gmail.com');


    $mail->Subject = "Subject Text";
    $mail->Body = "<i>Mail body in HTML</i>";


    $mail->addAddress("parkingston@gmail.com");

    if(!$mail->send()) 
    {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } 
    else 
    {
        echo "Message has been sent successfully";
    }

    ?>   

You can easily download this both file if you do not have it. 如果没有,您可以轻松下载这两个文件。 Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM