PHPMailer w / Gmail - 不工作

时间:2016-06-06 18:27:42

标签: php email phpmailer

我最近一直在学习PHP,我需要能够使用它发送电子邮件。

我发现PHPMailer是发送邮件的好方法,所以我试过了。我根据我能找到的所有示例设置了我的代码,但我仍然无法让它工作。

这是我的PHP代码:

<?php

error_reporting(E_ALL);

$fc = file_get_contents("http://redxtech.ca/fbm/");

echo $fc;


if (isset($_GET["name"]) && isset($_GET["email"]) && isset($_GET["m"])) {
    $name = $_GET["name"];
    $email = $_GET["email"];
    $msg = $_GET["m"];
}
else {
    $name = "Blank Name";
    $email = "<email here>";
    $msg = "Blank";
};

$e_msg = "FB:/nYou have recieved a new submission form from " . $name . " at <" . $email . ">./n/nIt says:/n/n" . $msg . "./n/nDo what you wish with this information./n~ Gabe";


require "PHPMailerAutoload.php";

$mail = new PHPMailer;

$mail->SMTPDebug = 1;

$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "<my gmail>";
$mail->Password = "<my super secret password>";
$mail->SMTPSecure = "tls";
$mail->Port = 587;

$mail->setFrom("<my gmail>", "Red's Mailer");
$mail->addAddress("<my other email>", "Gabe");
$mail->addAddress("<another email>", "FB");
$mail->addReplyTo("<my other email>", "Gabe");

$mail->isHTML = true;

$mail->Subject = "New Submission";
$mail->Body = $e_msg;
$mail->AltBody = "This is an altbody.";

if(!$mail->send()) {
    echo "<script>console.log('Mail was not sent')</script>";
    $errInf = $mail->ErrorInfo;
    echo "<script>console.log('Mailer Error: " . $errInf . "')</script>";
} else {
    echo "<script>console.log('Mail was sent')</script>";
}

?>

当我点击提交按钮发送上一页的表单时,它会将我带到/mail.php?name=aName&email=anEmail&m=aMsg和echo的页面,但它不会发送电子邮件。

当我打开Chrome开发工具时:

“在不安全的起源上不推荐使用devicemotion事件,并且将来会删除支持。您应该考虑将应用程序切换到安全的来源,例如HTTPS。有关详细信息,请参阅。”

但是,我很确定这是由嵌入式Vimeo播放器而非PHPMailer造成的。

如果有人能在这里帮助我,那就太棒了:D

1 个答案:

答案 0 :(得分:0)

我解决了自己的问题。

当我提到我认为它没有正确加载时,那是正确的一半。

要修复它,我将其余的.php文件添加到与自动加载器相同的目录中。我以为自动加载器会自动包含所有这些。

相关问题