使用Wordpress发送电子邮件

use*_*549 5 php wordpress sendmail

我尝试了很多不同的方法,但无法使用该mail()函数在PHP中通过SMTP成功发送电子邮件.

 <?php
require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer();
$phpmailer->SMTPAuth = true;
$phpmailer->Username = 'skchourasia@asselslutions.com';
$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('support@wordpressapi.com/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.";
 ?>
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我收到以下错误:

解析错误:语法错误,第8行的C:\ xampp\htdocs\wp-vtr\wp-content\themes\twentyeleven\content.php中的意外T_VARIABLE

 $phpmailer->IsSMTP(); // telling the class to use SMTP"
Run Code Online (Sandbox Code Playgroud)

nov*_*ato 1

这:

$phpmailer->FromName   = $_POST[your_email];
$phpmailer->Subject    = $_POST[your_subject];
$phpmailer->Body       = $_POST[your_message]; 

$phpmailer->MsgHTML($_POST[your_message]);
Run Code Online (Sandbox Code Playgroud)

应该是这样的:

$phpmailer->FromName   = $_POST['your_email'];
$phpmailer->Subject    = $_POST['your_subject'];
$phpmailer->Body       = $_POST['your_message']; 

$phpmailer->MsgHTML($_POST['your_message']);
Run Code Online (Sandbox Code Playgroud)

无论如何,您似乎正在尝试通过 PHPMailer 类和 mail() 本机 PHP 函数发送电子邮件。您可能只是在测试,但我不太确定您想做什么。