提交时,我正在wordpress上使用ajax发送一封联系电子邮件。从下面的代码中,您可以看到From标头已正确设置,但wordpress正在从phpmailer\\u init action中选择要设置为标头的标头。有人能帮我解决这个问题吗
add_action(\'wp_ajax_contact_form\', \'contact\');
add_action(\'wp_ajax_nopriv_contact_form\', \'contact\');
function contact(){
// if ($_SERVER[\'REQUEST_METHOD\'] == \'POST\') {
/* sanitize and validate */
$name = isset($_POST[\'name\'])? sanitize_text_field( $_POST[\'name\'] ) : null;
$phone = isset($_POST[\'phone\'])? sanitize_text_field($_POST[\'phone\']): null;
$email = isset($_POST[\'email\'])? sanitize_email( $_POST[\'email\'] ) : null;
$message = isset($_POST[\'message\'])? sanitize_text_field( $_POST[\'message\'] ) : null;
$subject = isset($_POST[\'subject\'])? sanitize_text_field( $_POST[\'subject\'] ) : null;
/* start sending */
$to = \'[email protected]\';
$headers = array(\'Content-Type: text/html; charset=UTF-8\', "From: $name <$email>");
// $headers[] = "From: $name <$email>";
$body = "Phone number: $phone <br><br> $message";
$sent = wp_mail($to, $subject, $body, $headers);
if($sent){
echo "Email delivered successfuly";
}
// }
}