我已經嘗試了很多不同的方法,但無法使用mail()
函數在PHP中通過SMTP成功發送電子郵件。使用Wordpress發送電子郵件
<?php
require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer();
$phpmailer->SMTPAuth = true;
$phpmailer->Username = '[email protected]';
$phpmailer->Password = 'password01';
$phpmailer->IsSMTP(); // telling the class to use SMTP
$phpmailer->Host = "mail.asselsolutions.com"; // SMTP server
$phpmailer->FromName = $_POST[your_email];
$phpmailer->Subject = $_POST[your_subject];
$phpmailer->Body = $_POST[your_message]; //HTML Body
$phpmailer->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$phpmailer->WordWrap = 50; // set word wrap
$phpmailer->MsgHTML($_POST[your_message]);
$phpmailer->AddAddress('[email protected]/files/', 'Wordpress support');
//$phpmailer->AddAttachment("images/phpmailer.gif"); // attachment
if(!$phpmailer->Send()) {
echo "Mailer Error: " . $phpmailer->ErrorInfo;
} else {
echo "Message sent!";
}
$to = $_REQUEST['to'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$from = $_REQUEST['from'];
$headers = "From:" . $from;
$mail = mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
我在做什麼錯?我收到以下錯誤:
Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\wp-vtr\wp-content\themes\twentyeleven\content.php on line 8
$phpmailer->IsSMTP(); // telling the class to use SMTP"
您的錯誤信息不完整,行號缺失。轉到該行號,並告訴我們前面幾行代碼是什麼。錯誤在那裏。 – Jocelyn
我已更新我的代碼,錯誤是在行否8 plz CHK它現在 – user1811549
即使您發佈的代碼不完美,我沒有看到任何可能導致解析錯誤的嚴重錯誤。它是否真的是你發佈的'content.php'的代碼? – Jocelyn