When I use wp_mail( $to, $subject, $message, $headers )
(with values in place, of course), the email gets sent with a from name and email that isn’t set anywhere I can find (not even in PHP or Apache settings). However, using mail( $to, $subject, $message, $headers )
instead works just fine. What could be happening with wp_mail()
to cause this?
Leave a Reply
You must be logged in to post a comment.
Hi @helenyhou:
You can set the header, just not with a parameter. WordPress uses “hooks” and the hooks you need are
'wp_mail_from'
and'wp_mail_from_name'
hooks.Here are the hooks you might add to your theme’s
functions.php
file to modify the"From:"
header when usingwp_mail()
to the email addressHelen Hou-Sandi <helenyhou@example.com>
:Well, if you’re using the
From: "Your Name" <youremail@example.com>rn
format in your headers, you shouldn’t be having a problem (unless you have a plugin installed which overrides the wp_mail function).However, as Mike said, you can filter the ultimate values with those filters, or you can just install this plugin:
Send From
It’ll give you an options setting to determine what name and email to use in
wp_mail()
.Sorry to revive an old question but isn’t it better to set via the headers like so:
That way you don’t have to worry about using a filter and then removing at after
wp_mail()
.It’s a bit of a hack but you can also use the
Reply To
header tag:$headers = 'Reply-To: "Aaren A. Aarenson" <aaron@somemail.com>';
Sadly this adds the email address to the From list, and replying means you will have to manually remove the address configured in the
wp_mail_from
filter.I had the same problem. For me it came out that the hosting provider (BlueHost) was preventing from changing the from field. Here they explain it https://my.bluehost.com/cgi/help/206 .
I fixed the problem by adding the email to cPanel mailboxes just as they say.