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 = "example@yahoo.com";
$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 registration@shoponline.com.au" ;
// send mail
mail($to,$subject,$message,$headers, "-r 4914031@yahoo.com");
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
$headers = "From: registration@shoponline.com.au" . "
" .
"Reply-To: registration@shoponline.com.au" . "
" .
"X-Mailer: PHP/" . phpversion();
UPDATE 2 :
with sender name
$headers = "From: Sender_Name<registration@shoponline.com.au>" . "
" .
"Reply-To: registration@shoponline.com.au" . "
" .
"X-Mailer: PHP/" . phpversion();
This issue stems from you missing a colon in your headers string:
$headers = "From: registration@shoponline.com.au" ;
^ here
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 -f
parameter 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.
Example:
-finfo@domain.tld
shall make your emails show up as coming from info@domain.tld
. Notice the lack of space after the -f
parameter.
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:
v=spf1 +a +mx +ip4:<ip address> ?all
Some servers will only recognize a TXT DNS entry with the same setup.