I am trying to send automated emails with a clean "From" address. When it sends the email its using the name I want with @my-website.com attached right after, how do I get rid of it?
Example
$address = "user@example.com";
$subject = "Confirmation";
$msg = "Registered";
$headers = "From: MyWebsite \r\n";
mail($address, $subject, $msg, $headers);
The result I get in my inbox when I test it is, MyWebsite@my-开发者_开发问答website.com instead of just MyWebsite
I think
$headers = "From: MyWebsite <MyWebsite@my-website.com> \r\n";
would do
If not, try reading http://www.sitepoint.com/advanced-email-php/
It's working correctly. You need the complete domain with mail()
it's required for the mail()
function to parse and legally under the CAN-SPAM
act.
Try this:
$headers = "From: MyWebsite <MyWebsite@my-website.com> \r\n";
This will show the name "MyWebsite" in most email clients, and also includes your email address. (Valid email should have a real From: email address.)
Try setting the from address to the string (including the quotes):
"MyWebsite" <whatever@my-website.com>
You can't specify MyWebsite
as sender because it's not a valid email address. You could try the following code:
$headers = "From: MyWebsite <whatever@my-website.com> \r\n";
精彩评论