Send mail() using php but Sender name always Apache

436

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!

131

Answer

Solution:

set your header like

$headers = "From: [email protected]" . "\r\n" .
           "Reply-To: [email protected]" . "\r\n" .
           "X-Mailer: PHP/" . phpversion();

UPDATE 2 :

with sender name

$headers = "From: Sender_Name<[email protected]>" . "\r\n" .
           "Reply-To: [email protected]" . "\r\n" .
           "X-Mailer: PHP/" . phpversion();
134

Answer

Solution:

This issue stems from you missing a colon in your headers string:

$headers = "From: [email protected]" ;
                ^ here

Add that in, and it should work as expected.

116

Answer

Solution:

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:

[email protected]

shall make your emails show up as coming from[email protected]. 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:

  • make sure your server has the appropriate reverse DNS records (PTR) set. Many - expecially shared hosting services do not assign them and you have to explicitly ask them to set them up for you. You may check your records with one of the many websites featuring general DNS utilities. Here's a random website doing that.

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.

People are also looking for solutions to the problem: php - Change main view position codeigniter

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.