wordpress的wp_mail中不能添加From email


From email couldn't be added in wp_mail in wordpress

我一直在尝试将回复邮件添加到wordpress功能wp_mail中。所以,我做了如下:

$subject = 'Inquiry from ' . $_REQUEST['first_name'] . ' ' . $_REQUEST['last_name'];
$headers = 'From: ' . $_REQUEST['first_name'] . ' <' . $_REQUEST['email_address'] . '>' . "'r'n";
if( wp_mail('to@example.com', $subject, $email_template, $header ) ){
    echo "sent";
}

在标题部分,如果我添加硬编码的电子邮件地址,它的工作,即

$headers = 'From: ' . $_REQUEST['first_name'] . ' <from@example.com>' . "'r'n";

但是当我把变量而不是硬编码时,它不起作用。你能告诉我怎么修理它吗?

首先,在wp_mail函数之前回显$_REQUEST['email_address']变量,以查看它是否返回期望的值。

第二,看这个。

if( wp_mail('to@example.com', $subject, $email_template, $header ) )

这里使用的是$header

而你有

'$headers' = 'From: ' . $_REQUEST['first_name'] . ' <' . $_REQUEST['email_address'] . '>' . "'r'n";

'$headers'为你的头定义。