Send mail() using php but Sender name always Apache
I really need a quick fix and haven't found any solution to my problem. I want to send email to the user but the sender name always shows Apache.
Here is my coding.
<?php $password = rand(1000,9999); $firstname = "syamsul"; $surname = "rizal"; $email = "[email protected]"; $max_id = 3; //Generate Email $to = $email; $subject = "Welcome to ShopOnline!"; $message = "Dear " .$firstname. ", welcome to use ShopOnline! Your Customer id is " .$max_id. " and the password is ".$password."."; $headers = "From [email protected]" ; // send mail mail($to,$subject,$message,$headers, "-r [email protected]"); echo "Thank you for sending us feedback"; ?>
And why i can't send this email to gmail account but works to non-gmail account? Thanks in advance!
set your header like
UPDATE 2 :
with sender name
This issue stems from you missing a colon in your headers string:
Add that in, and it should work as expected.
With regards to the second part of your question (gmail not accepting emails), there's a very large amount of considerations to be made.
First of all you should check the mail related php.ini sections. It's possible to specify a
-fparameter that on some servers shall change the originating mail name from the server's default one (like in example "postmaster" and others) to your desired name.
shall make your emails show up as coming from
[email protected]. Notice the lack of space after the
Depending on how picky the destination email servers are, this alone may make your emails to be accepted. In fact many of them, as anti-spam measure check consistency between email headers and reported sender.
But that's not enough.
Some destination servers will still reject your emails or automatically put them in the spam folder.
To avoid that, there are several measures. Some of the basic tasks to perform are DNS related:
You have also to set other DNS entries, namely the SPF record with appropriate setup like:
Some servers will only recognize a TXT DNS entry with the same setup.