• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

php mail not sending once I add headers

Why does the below code not send my email? When I remove the "headers" variable from the mail function, it sends right away with no problems.

My $to and $subject and $html vars are set further up but as I said, it works fine as soon as I remove the $headers

I'm trying to send html encoded email.
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <$to>' . "\r\n";
$headers .= 'From: Birthday Reminder <me@somewhere.com>' . "\r\n";


Open in new window

2 Solutions
try this:

//email headers
$headers = "From: from name <test@email.com>\r\n";
$headers .= "Reply-To: test@email.com\r\n";
$headers .= "Date: " . date ( "r" ) . "\r\n";
$headers .= "Return-Path: test@email.com\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Message-ID: " . date ( "r" ) . "mail.yourdomian.com\r\n";
$headers .= "Content-Type: text/html;charset=iso-8859-1\r\n";
$headers .= "X-Mailer: PHP Mailer 1.0\r\n";
mail ( $to, $subject, $text, $headers, '-f' . $to );

Open in new window

AbendagoAuthor Commented:
nope, still didn't arrive
Mark BradyPrincipal Data EngineerCommented:
//<!-- Generate email for the seller <!-->
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "From: you@yourplace.com" . "\r\n";
$headers .= "Reply-To: you@yourplace.com" . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

$subject = "Your Subject";

$message= "This is your message or body";

$send_mail = mail($email,$subject,$message,$headers);

// Tried and tested
By the way, are you sending this from a local server or an online server? The above script works for me when on the online server but when I try to run it on my local server it does not send. Must be something in the local settings I guess. Anyway, hope that helps.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now