0

所以我正在尝试使用 PHPMailer 来处理我网站上的电子邮件表单。

我根据我找到的教程在这里编写了代码。

<?php
        error_reporting(E_ALL);
        require_once("class.phpmailer.php");
        include("class.smtp.php");

        $email = new PHPMailer();

        //
        // Set server details for send
        //
        $email->IsSMTP();
        $email->Host = "mail.loganyoung.za.net";
        $email->Port = 25;
        $email-SMTPAuth = true;
        $email->Username = "<my email>";
        $email->Password = "<my password>";

        //
        // Send mail from the contact form
        //
        $to = "<my email>";
        $from = $_POST["from"];
        $name = $_POST["name"];
        $subject = "From web: ".$_POST["subject"];
        $message = $_POST["message"];

        $body = "<p>Hi Logan,</p>";
        $body .= "<p>You have received a new query on your website.<br />Please see below:</p>";
        $body .= "<p>";
        $body .= str_replace("\r\n", "<br />", $message);
        $body .= "</p>";

        $email->SetFrom($from, $name);
        $email->AddReplyTo($from, $name);
        $email->AddAddress($to, "LoganYoung.za.net");
        $email->Subject = $subject;
        $email->Body = $body;
        $email->IsHTML = true;

        session_start();
        if(!$email->Send()) {          
                $_SESSION["mailresult"] = "success";
                echo "success";
        } else {
                echo "<p>Failed:</p><p>".$email->ErrorInfo."</p>";
                $_SESSION["mailresult"] = "failed";
                $_SESSION["mailerror"] = $email->ErrorInfo;
        }

?>

我认为它未发送的可能原因可能是......

  • 不正确的 SMTP 详细信息(可能在没有 SMTP 身份验证的情况下发送?)
  • 处理程序没有获取 POST 数据(发送它的 ajax 似乎工作正常)
  • 这段代码有一些我无法识别的问题......

作为消除可能性的一种方法,任何人都可以发现这里的代码有什么问题吗?如果是这样,出了什么问题,我该如何解决?

提前致谢!

4

1 回答 1

1
$email-SMTPAuth = true;

这不应该是:

$email->SMTPAuth = true;
于 2013-10-30T21:52:30.700 回答