php mail not sending once I add headers

Posted on 2009-12-31
Medium Priority
Last Modified: 2013-12-13
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

Question by:Abendago

Accepted Solution

like_php earned 500 total points
ID: 26155897
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


Author Comment

ID: 26156078
nope, still didn't arrive
LVL 20

Assisted Solution

by:Mark Brady
Mark Brady earned 500 total points
ID: 26156332
//<!-- 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.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question