php mail not sending once I add headers

Posted on 2009-12-31
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 <>' . "\r\n";


Open in new window

Question by:Abendago
    LVL 1

    Accepted Solution

    try this:

    //email headers
    $headers = "From: from name <>\r\n";
    $headers .= "Reply-To:\r\n";
    $headers .= "Date: " . date ( "r" ) . "\r\n";
    $headers .= "Return-Path:\r\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Message-ID: " . date ( "r" ) . "\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

    nope, still didn't arrive
    LVL 20

    Assisted Solution

    by:Mark Brady
    //<!-- Generate email for the seller <!-->
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "From:" . "\r\n";
    $headers .= "Reply-To:" . "\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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    The viewer will learn how to dynamically set the form action using jQuery.
    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.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now