How can I send email with PHP (without being caught as spam)

Here is an example of a working PHP script to send mail, which properly utilizes the reply-to header to set your response address, and set's the from address to a user and domain that you control.

<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "scott@britepencil.com";
$subject = "Contact Form";
$mailheader = "From: $recipient \r\n" . "Reply-To: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
Was this answer helpful?

Related Articles

How do I set up my BlackBerry to check my Business Email?

From the BlackBerry home screen, click BlackBerry Setup > Set up Internet Email > Add An...

503 valid RCPT command must precede DATA

When sending email, you receive an immediate bounce such as the following:Subject: RE: XXXXXX -...

How do I change my email password?

There are three ways to do this: Through the Customer Portal, through cPanel, or if you already...

Why does mail from my script show a different email address?

Our servers have re-write enabled. This is a valuable tool in the fight against fraudulant email...

How do I get Internet Headers in Outlook?

When troubleshooting emails the headers are crucial to sorting out problems. Here is how to get...