Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

PHP Mail Headers issue

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Rudy

Established Member
Impact
16
Hey guys,
For the life of me, I can not get the "From" and "Reply-To" email to show up correctly.

When I send this form to my gmail account (and insert my gmail email address in as the "From" & Reply-To) here's what I get: "@ gmail. com reply-to"

That's including the spaces.

Everything else is showing up correctly.

Ok, so here's my current PHP code:
Code:
$headers = "From: $_POST[email] \n " .
                  "Reply-To: $_POST[email]";
                 $message =
 		"First Name: ".$_POST[name]." \n
 		E-mail Address: ".$_POST[email]." \n
 		Phone Number: ".$_POST[phone]." \n
 		Maiiling Address: ".$_POST[street]." \n
 		".$_POST[city].", ".$_POST[state]." ".$_POST[zip]." \n
 		Questions and Comments: ".$_POST[questions]." \n";
 		mail("my email address", "Submission from Website", $message, $headers);

Any idea what's wrong? Thanks in advance.

- David
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Headers need to be separated by a CRLF, \r\n.
 
0
Close
Thanks for the response. I made that change, and here's what I'm getting now:

"@ gmail. com reply-to" <FrontPartofGmailAddress>, [email protected]

Where "FrontPartofGmailAddress" is ... well... the obvious. Spaces are also there.

Here's the code of my current header, one more time (with that change):
Code:
$headers = "From: $_POST[email] \r\n " .
                  "Reply-To: $_POST[email]";
 
0
Close
This is what I use - always has worked for me:

PHP:
		$headers = "From: [email protected]\n";
		$headers .= "Reply-To: [email protected]\n";
		$headers .= "Return-Path: [email protected]\n";
		$headers .= "Sender: [email protected]\n";
		$headers .= "MIME-Version: 1.0\n";
		$headers .= "Content-type: text/plain; charset=UTF-8\n";
		$headers .= "Content-transfer-encoding: 8bit\n";
		$headers .= "X-Priority: 3\n";
		$headers .= "X-MSMail-Priority: Normal\n";
		$headers .= "X-Mailer: PHP/" . PHP_VERSION . "\n";
		$headers .= "X-MimeOLE: Produced By PHP/" . PHP_VERSION . "\n";
 
0
Close
Thanks, Eric. The problem is, the information is being submitted via the POST method of an HTML form. I need the posted email address (named "email") to be the "From" and "Reply-to" email address.
 
0
Close
Well...

You can do this:

PHP:
if (preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>]+\.+[a-z]{2,6}))$#si', $_POST['email']))
{
	$headers = "From: {$_POST['email']}\n";
	$headers .= "Reply-To: {$_POST['email']}\n";
	$headers .= "Return-Path: {$_POST['email']}\n";
	$headers .= "Sender: {$_POST['email']}\n";
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/plain; charset=UTF-8\n";
	$headers .= "Content-transfer-encoding: 8bit\n";
	$headers .= "X-Priority: 3\n";
	$headers .= "X-MSMail-Priority: Normal\n";
	$headers .= "X-Mailer: PHP/" . PHP_VERSION . "\n";
	$headers .= "X-MimeOLE: Produced By PHP/" . PHP_VERSION . "\n";

	$message = "First Name: " . $_POST['name'] . "\nE-mail Address: " . $_POST['email'] . "\nPhone Number: ".$_POST['phone'] . "\n";
	$message .= "Maiiling Address: " . $_POST['street'] . "\n" . $_POST['city'] . ", " . $_POST['state'] . " " . $_POST['zip'] . "\n";
	$message .= "Questions and Comments: " . $_POST['questions'] . "\n";
	mail('my email address', 'Submission from Website', $message, $headers);
}
else
{
	echo 'Email invalid.';
}

I added a basic email validation - but a small note: you should validate/sanitize the other inputs as well :)
 
Last edited:
1
Close
That got it working! Thanks a ton!
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back