Forum Moderators: coopster

Message Too Old, No Replies

Email "From" Problem

Sending email from a PHP form through server

         

cookie2

5:15 pm on Oct 7, 2004 (gmt 0)

10+ Year Member



I have a minor problem using a PHP script to send form data from a contact page. The script works as it should in that it processes and sends the data to the mail function of the server and it is then sent out.

When the sent mail is received at my mailbox at either of my two paid ISP's (Comcast and Earthlink), it is perfect. But when I have it sent to a web based email address like yahoo.com or go.com, the "from" name gets completely messed up.

Instead of showing as "John Smith" on the web based ones, it shows as "John@wmailmsg05.seamail.go.com" which is the server it's coming in on, not being sent from. Email.com munges it up even worse.

Is this something that I can improve and control by tweaking the PHP script or will I just have to live with it?

Timotheos

5:32 pm on Oct 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd be interested to see what the From: part of your header looks like.

For example, this is the way I have it set up
$headers .= "From: John Smith <jsmith@example.com>\r\n";
mail($to, $subject, $message, $headers);

cookie2

12:20 am on Oct 10, 2004 (gmt 0)

10+ Year Member



My headers are set from the script using the following:

$from_address = $_POST['name'];

// CLEAR HEADERS
$headers = "";

// ADD FROM ADDRESS
if($from_address!= "") {
$headers .= "From: $from_address\r\n";
}

mhbweb

12:15 pm on Oct 10, 2004 (gmt 0)

10+ Year Member



i have a related question, i hope you dont mind me popping it in here..

ive tried to

ini_set("sendmail_from","me@email.com");

but it just fails to set it, what am i doing wrong?

jamesa

12:36 pm on Oct 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That'll happen if you have just a name without an email address in the FROM field. Timotheos is exactly right. Syntax should be:

name <email@domain.tld>

You can exclude the name and just have this:

<email@domain.tld>

or this:

email@domain.tld

But if you send the name without an email address the receiving end of it will often assume it's an local address and "complete" it for you.