PHP Mail

Posted on 2011-05-03
Last Modified: 2012-05-11
I see from the PHP manual that the headers for the mail are just a string with a CRLF between each header element::

$headers = "From:" . "\r\n" ."CC:";

But I've been using some code I copied from somewhere that makes the headers an array, and I'm just wondering why or how that works:

$from = "sender<>";
$host = "localhost";
$username = "";
$password = "early237";
$headers = array ('From' => $from,
        'To' => $To,
        'Subject' => $Subject);
$smtp = Mail::factory('smtp',
        array ('host' => $host,
            'auth' => true,
            'username' => $username,
            'password' => $password));
$mail = $smtp->send($To, $headers, $Body);

Thanks for any enlightenment.
Question by:steva
    LVL 26

    Accepted Solution

    PHP's mail function and the Mail class that you see being used are not the same.

    Author Closing Comment

    Ah!  Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    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.

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now