I am creating a contact form on WordPress site.
The form is perfectly working with following code:
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
my_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($topic) || empty($message)){
my_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
}
}
}
}
else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
?>
However, this sends email with 'From' name as 'WordPress'.
I want to customize 'WordPress' with sender name for which I am using $name variable, so that I got to know who send me email without opening it.
Any help will be appreciated.
I am creating a contact form on WordPress site.
The form is perfectly working with following code:
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
my_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($topic) || empty($message)){
my_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
}
}
}
}
else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
?>
However, this sends email with 'From' name as 'WordPress'.
I want to customize 'WordPress' with sender name for which I am using $name variable, so that I got to know who send me email without opening it.
Any help will be appreciated.
Share Improve this question asked Aug 26, 2019 at 14:07 KA.MVPKA.MVP 33 bronze badges2 Answers
Reset to default 0$to = '[email protected]';
$name= 'jhon';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('From: '.$name.'');
wp_mail( $to, $subject, $body, $headers );
I hope it'll work as you want.
The simplest way to change this for ALL outbound mail generated by your site is a plugin called CB Change Mail Sender. I have used it a lot. Performance is not an issue.