PHP-使用PHPMailer从XAMPP发送邮件

时间:2018-08-30 12:13:38

标签: php email xampp phpmailer

当我单击发送按钮时没有任何反应,希望您能帮助我找到解决方案。在我的php.ini中,我只是更改了电子邮件

[邮件功能]

; XAMPP:如果要使用像Mercury这样的SMTP服务器,请注释掉此内容

; SMTP =本地主机

; smtp_port = 25

;仅适用于Win32。

; http://php.net/sendmail-from

; sendmail_from = myemail@yahoo.fr

forgotPassword.php

<div>
    <div>
        <div>
            <input type="email" class="form-input" id="email" placeholder="Your email">
        </div>
    </div>

    <div>
        <input type="submit" class="btn-reset" value="Send">
    </div>

    <p id="response"></p>
</div>

<script>
    var email = $("#email");

    $(document).ready(function()
    {
        $(".btn-reset").on('click', function()
        {
            if(email.val() != "")
            {
                email.css('border', '1px solid dodgerblue');

                $.ajax(
                {
                    url: 'forgotPassword.php',
                    method: 'POST',
                    dataType: 'json',
                    data:
                    {
                        email: email.val()
                    },
                    success: function (response)
                    {
                        if(!response.success)
                        {
                            $("#response").html(response.msg).css('color', 'red');
                        }
                        else
                        {
                            $("#response").html(response.msg).css('color', 'green');    
                        }
                    }
                });
            }
            else
            {
                email.css('border', '1px solid red');
            }
        });
    });
</script>

在同一页面

$query = mysql_query('SELECT * FROM user WHERE email = "'.$email.'"')or die(mysql_error());

if(mysql_num_rows($query) > 0)
{
    require_once "PHPMailer/PHPMailer.php";
    require_once "PHPMailer/Exception.php";

    $mail = new PHPMailer();
    $mail->addAddress($email);
    $mail->setFrom("myname@yahoo.fr", "ME");
    $eail->Subject = "Email";
    $mail->isHTML(true);
    $mail->Body = "
        Hi my friend!
    ";


    if($mail->send())
    {
        exit(json_encode(array("status" => 1, "msg" => "Email sent! ")));
    }
    else
    {
        exit(json_encode(array("status" => 0, "msg" => "Error sending mail")));
    }
}
else
{
    exit(json_encode(array("status" => 0, "msg" => "Check your email")));
}

0 个答案:

没有答案