From appearing mysetriously in e-mail

I have a form that e-mail’s me a user’s comments.

The strange thing is, is that the “FROM” address is appearing in the e-mail even though I never include it in my mail() statement.

How is that possible?!


	// Check for Data-Entry Errors.
	if (empty($errors)){
		// Form data clean.

		// E-mail Inquiry to Administrator.
		$to = 'debbie@mail.com';
		$subject = $trimmed['subject'];
		$inquiry = $trimmed['inquiry'];
//		$from = $trimmed['senderEmail'];
		mail($to, $subject, $inquiry);
	}

When I get the e-mail in my inbox I see…


Subject:	Test
From:		user1@user1s-macbook.local
Date:		Mon, Oct 10, 2011 9:31 pm
To:		debbie@mail.com

Sincerely,

Debbie

If you don’t specify a “From” header PHP will insert the default server address so that the email has a valid sender. Otherwise your emails will look like spam.

So what is the proper syntax to get who is sending me the comments from the form? (i.e. the sender’s e-mail)

Debbie

Use the additional_headers parameter of the mail function. Use the $from variable and add it as the 4th parameter.

// E-mail Inquiry to Administrator.
        $to = 'debbie@mail.com';
        $subject = $trimmed['subject'];
        $inquiry = $trimmed['inquiry'];
        $from = 'From: '. $trimmed['senderEmail'] ."\\r\
";
        mail($to, $subject, $inquiry, $from);

1.) Why do you have \r
at the end of the $from variable?

2.) Can you name the parameters anything in mail()??

I thought you have to use mail($to, $subject, $body, $headers)?

Debbie

Bacause that is the separator that you have to use between headers.

The values you are passing in are To, Subject, Body, and Headers. What variables you set up to contain those values is up to you.

In this case since the only header you are supplying is the From header it is just as easy to call it $from as to call it $headers as from is more descriptive of what it currently contains.

Okay, thanks.

Debbie