Knowledgebase

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

  • php, code, mail, script, contact form
  • 0

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?
« Back