最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to customize 'WordPress' in sent email using wp_mail function?

programmeradmin0浏览0评论

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 badges
Add a comment  | 

2 Answers 2

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.

发布评论

评论列表(0)

  1. 暂无评论