使用PHPMailer发送邮件不';行不通
所以我尝试使用PHPMailer来处理我网站上的电子邮件表单 我根据找到的教程在这里编写了代码使用PHPMailer发送邮件不';行不通,php,email,phpmailer,Php,Email,Phpmailer,所以我尝试使用PHPMailer来处理我网站上的电子邮件表单 我根据找到的教程在这里编写了代码 <?php error_reporting(E_ALL); require_once("class.phpmailer.php"); include("class.smtp.php"); $email = new PHPMailer(); // // Set server details for
<?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数据(不过发送POST数据的ajax似乎工作正常)
- 这个代码有一些我无法识别的问题
$email-SMTPAuth = true;
这不是应该是:
$email->SMTPAuth = true;
这个
if(!$email->Send()){
应该是if($email->Send()){
没有!
-这表示如果没有/NO email…
-!
是PHP中的否定符号。很好。我已经更新了代码,但似乎没有帮助。我在Chrome的开发工具中看到,会话没有被创建