downloads | documentation | faq | getting help | mailing lists | reporting bugs | sites | links | my 
search for in the  
view the version of this page
Last updated: Thu, 21 Aug 2003

XLVIII. Mail functions


The mail() function allows you to send mail.


For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time. If you use another mail program, such as qmail or postfix, be sure to use the appropriate sendmail wrappers that come with them. PHP will first look for sendmail in your PATH, and then in the following: /usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib. It's highly recommended to have sendmail available from your PATH. Also, the user that compiled PHP must have permission to access the sendmail binary.


There is no installation needed to use these functions; they are part of the PHP core.

Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Table 1. Mail configuration options

For further details and definition of the PHP_INI_* constants see ini_set().

Here's a short explanation of the configuration directives.

SMTP string

Used under Windows only: DNS name or IP address of the SMTP server PHP should use for mail sent with the mail() function.

smtp_port int

Used under Windows only: Number of the port to connect to the server specified with the SMTP setting when sending mail with mail(); defaults to 25. Only available since PHP 4.3.0.

sendmail_from string

Which "From:" mail address should be used in mail sent from PHP under Windows.

sendmail_path string

Where the sendmail program can be found, usually /usr/sbin/sendmail or /usr/lib/sendmail. configure does an honest attempt of locating this one for you and set a default, but if it fails, you can set it here.

Systems not using sendmail should set this directive to the sendmail wrapper/replacement their mail system offers, if any. For example, Qmail users can normally set it to /var/qmail/bin/sendmail or /var/qmail/bin/qmail-inject.

qmail-inject does not require any option to process mail correctly.

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

Table of Contents
ezmlm_hash -- Calculate the hash value needed by EZMLM
mail -- send mail

add a note add a note User Contributed Notes
Mail functions
Patrice Levesque
31-Oct-2003 12:27
Please be aware that the SendMail() function below (provided by kieran dot huggins at rogers dot com) may send all mail twice when using qmail.

The mail() function in PHP (at least 4.2.3) has a "To:" parameter and a extraheader parameter.  If you specify a "To:" manually using the extraheaders, it *doesn't* override the first "To:" parameter.  Qmail must then receive two "To:" and send twice.

Just comment-out the line that adds the "To:" to the extraheaders to make the below script work.
Allen Brooker
20-Oct-2003 08:48
RFC's 2822 and 822 ( ) both specify that \r\n line endings should be used both in the headers and message body.

However, it is becoming my experiance that \n seems to work for the majority with \r\n double-line spacing the message and pushing the custom headers into the body =|

Allen Brooker
Andrew Cope
27-Sep-2003 12:40
If you're using exim as your sendmail replacement, and you want to use the -f directive, make sure you put your apache user in exim's trusted_user list.

For example, on my web server, www-data is the apache user so I had to put this line in exim.conf before the -f flag would work:

  trusted_users = www-data

nes at techie dot com
27-Sep-2003 12:36
I've noticed some anti-spam email programs also deny delivery to mail that doesn't have a Message-ID.  Even though it is legal to do so, many domains will consider the email spam and drop it. 

Using sendmail on a win2k server, there is no Message-ID on some test mailings I've done.  The ones that are added were there due to the filtering software added it afterwards, at least that's what the spamheaders error code database says.
10-Sep-2003 03:35
If one uses header info containing Content-type: text/html, then you may have issues with new lines.
If the user views in plain text, then <br> shows in the text.
If one relies on \r\n then it will not work because of the html content type.

Use a content type of text/plain instead.

$header = "Content-type: text/plain; charset=iso-8859-1\r \n";

So my header info looks like:

    $headers = "MIME-Version: 1.0\r \n";
    $headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";
    $headers .= "From: \"$myname\" <$myemail>\r \n";
    $headers .= "Reply-To: \"$myname\" <$myemail>\r \n";
    $headers .= "X-Priority: 3\r \n";
    $headers .= "X-MSMail-Priority: High\r \n";
    $headers .= "X-Mailer: Just My Server";

This gives good results from a linux server and email appears correctly in MS Outlook Express ans hotmail(particularly fussy w/ headers).

Thus the $message newlines correctly too, instead of being run together if Content Type is text/html

    $message = "Thank you for your enrolment.\r\n";
    $message .= "Your member name is $member_name.\r\n";

ng4rrjanbiah at rediffmail dot com
29-Aug-2003 07:20
For Windows users who work on local machine:

If you want to send emails from your local machine you can try ArGoSoft Mail Server ( )

1. Install ArGoSoft Mail Server
2. Open the ArGoSoft Mail Server and click Tools > Options to configure.
3. Enter the DNS server name or let the ArGoSoft Mail Server to auto-detect.
4. In the IP Homes tab, enter
5. Start (run) the ArGoSoft Mail Server and make sure there is no error.
6. Now, the "localhost" ( is your SMTP & POP3 server.

1. Open your php.ini
2. Enter the value of SMTP like SMTP = localhost

That's all!

Do not trust "sendmail_from" of php.ini. Always set headers parameter in mail() function.

R. Rajesh Jeba Anbiah
hzmz at bofh dot auca dot kg
24-Jul-2003 06:16
If you are trying to send mail and you are in chroot. You can do it via your smtp server.

include_once 'Mail.php';

$headers['Subject'] = 'Your subject';
$headers['From'] = '';
$params['host'] = '';
$mailer = &Mail::factory('smtp'$params);
$status =$mailer->send(''$headers'your message');
if (
PEAR::isError($status)) {

Thanks to Horde team:
Jeff Means <meaje at meanspc dot com>
07-Jul-2003 02:50
I noticed when sending html mail to ms outlook 2000 outlook will not interpret correctally the headers unless you place a space between the \r\n appending the header line so that it looks like:

$header = "From: somebody <>\r \n";

This seems to work in all other email clients I have tried it on so far (Mozilla, TWIG) without breaking them.  Trust M$ to use screwy headers.  The behavior I recieved out of outlook was that the first header was recognized as a header and all other headers after that one were placed in the body of the message.

Angelo - Columbus, OH
26-Jun-2003 04:00
It is a good idea to add the Date header to the headers of sent messages:

$header = "Date: " . date("r");
Tomislav Drpic -
01-Jun-2003 01:11
While working with a system that would send a lot of emails, I wanted to skip the local antivirus program (Amavis with local relay virus check) so that sending the emails won't load the server heavily.  Also, I needed to change the "Return-path:" header of the message.

This is the solution I came up with:


"Here we put the content of the message.";

$sender "";

$sendmail "/usr/sbin/sendmail -t -f $sender -C /etc/";

Notice that sendmail is receiving three params:
Scan the To:, Cc:, and Bcc: from the message itself

-f <email address>
Change the envelope (Return-path:) of the message

-C <config path>:
Use a different configuration file for sendmail, in this case the config file
skips the virus check

$fd popen($sendmail"w");
fputs($fd"From: \"Sender Name\" <$sender>\r\n");
fputs($fd"Subject: Finally\r\n");
fputs($fd"X-Mailer: Mailer Name\r\n\r\n");

Notice that this script will be called from a cron job as root (sendmail won't let you use a different config file unless you are root).
flobee at gmx dot net
28-May-2003 06:56
while trying and trying to get text and html mails run... (both: Win / linux:
the one and only fault a made is the the "boundary" definition!
create your own boundary:
$myboundary = "NO_SPACES_SIMPLE_LETTERS_MY_NAME". md5(rand()) ."";

define the boundary:
// in one line
$headers .= "Content-Type: multipart/mixed; boundary=\"$myboundary\"\n";

// using the boundary: "--" starts it
$headers .= "--$myboundary"

// ending it "--" at least!!!
$headers .= "--$myboundary--"
grey at greywyvern dot com
09-May-2003 12:23
Here's a function I'm continually working at to send multiple emails while only opening the socket once (much faster than mail()) while sending a separate email to each address.  It also includes many headers which you can adjust to your liking.  Note the comment which explains the array format for incoming "To:" addresses.


function socketmail($toArray$subject$message) {
// $toArray format --> array("Name1" => "address1", "Name2" => "address2", ...)


$connect fsockopen (ini_get("SMTP"), ini_get("smtp_port"), $errno$errstr30) or die("Could not talk to the sendmail server!"); 
$rcv fgets($connect1024); 

fputs($connect"HELO {$_SERVER['SERVER_NAME']}\r\n");
$rcv fgets($connect1024); 

  while (list(
$toKey$toValue) = each($toArray)) {

$rcv fgets($connect1024); 
fputs($connect"RCPT TO:$toValue\r\n"); 
$rcv fgets($connect1024); 
$rcv fgets($connect1024); 

fputs($connect"Subject: $subject\r\n"); 
fputs($connect"From: My Name <>\r\n"); 
fputs($connect"To: $toKey  <$toValue>\r\n"); 
fputs($connect"X-Sender: <>\r\n"); 
fputs($connect"Return-Path: <>\r\n"); 
fputs($connect"Errors-To: <>\r\n"); 
fputs($connect"X-Mailer: PHP\r\n"); 
fputs($connect"X-Priority: 3\r\n"); 
fputs($connect"Content-Type: text/plain; charset=iso-8859-1\r\n"); 
fputs($connectstripslashes($message)." \r\n"); 

$rcv fgets($connect1024); 
$rcv fgets($connect1024); 

fputs ($connect"QUIT\r\n"); 
$rcv fgets ($connect1024); 

michael a at mac dott com
03-May-2003 01:57
If you are getting slash characters replacing single and double quotes and apostrophes - like ' becoming /' - then apparently there is an issue with your php.ini file.

But the easy way to fix it is to use the function 'stripcslashes'.

Just use:

<?php mail$to stripcslashes($subject) ,  stripcslashes($message) ...

Took me hours to find it.

untold at punkass dot com
17-Apr-2003 04:13
Here's the final solution for me:
mfloryan at bigfoot dot com
22-Mar-2003 12:51
A brief comment on the "\r\n" in headers:
Recent email scanners (virus scanners) working on mail servers will refuse to deliver any mail containing the "\r" character in header (your mail will probably bounce off with "Disallowed MIME characters found in headers" comment).
This is true for Qmail-Scanner and F-Prot Antivirus for Linux but for others most probably too.
Hence use "\r\n" in headers ONLY when you send you email using the mail() function via Windows-based SMTP server - otherwise just use "\n"
13-Mar-2003 07:53
Never forget the header
Content-type: text(/html); charset=iso-XXXX-XX\r\n"; (Where XXXX-XX stands for the charset and HTML is optional - don't write HTML when you send plain text mails)

If you forget to set this header, Outlook Express shows the mail correctly but Outlook has probs with it.

Outlook build 9: No newlines will appear in the mail
Outlook build 10: After every line a second newline will appear.

After setting the header, the mail will be shown correct in all email programs.

(Keywords: newline, outlook, outlook express, \n\r, \r\n, double newlines, no newline)
11-Mar-2003 12:41

I found a link here...

...which shows how to utilize the CDONTS COM
object when running PHP under IIS.

@$CDONTS = new COM("CDONTS.NewMail");

$CDONTS->From "";
$CDONTS->To "";

$CDONTS->BodyFormat 0;
$CDONTS->MailFormat 0;


@$CDONTS->Subject "Using CDONTS with PHP4 and IIS";
$CDONTS->Body "Blah blah blah blah, bleh...";


"Mail sent";

The only problem is (and this is where I am hoping
to get some input from others) when I run this code,
it received over 200 emails, and there were still
another 1000+ emails queued on the server (and that
was just when I was finally able to kill it).

Anyone have any explainations, or better examples?
ronan dot minguy at wanadoo dot fr
21-Feb-2003 12:45
If you want to send an email in HTML with accent letters (for non-only-english speaking people) or the euro sign, put this in your header :
Content-Type: text/html; charset=iso-8859-15

f dot touchard at laposte dot net
31-Jan-2003 11:46
***Encoding plain text as quoted-printable in MIME email***

If you don't want to install IMAP and use imap_8bit() to encode plain text or html message as quoted-printable
(friendly french special characters encoding :-) in MIME email, try this function.
I haven't fully tested it ( like with microtime with long mails). I send html message as 7-bit, so I didn't try yet with html.
If you have good html practise, you don't really need to encode html as quote-printable as it only uses 7-bit chars.

function qp_encoding($Message) {
    /* Build (most polpular) Extended ASCII Char/Hex MAP (characters >127 & <255) */
    for ($i=0; $i<127; $i++) {
        $CharList[$i] = "/".chr($i+128)."/";
        $HexList[$i] = "=".strtoupper(bin2hex(chr($i+128)));

    /* Encode equal sign & 8-bit characters as equal signs followed by their hexadecimal values */
    $Message = str_replace("=", "=3D", $Message);
    $Message = preg_replace($CharList, $HexList, $Message);

    /* Lines longer than 76 characters (size limit for quoted-printable Content-Transfer-Encoding)
        will be cut after character 75 and an equals sign is appended to these lines. */
    $MessageLines = split("\n", $Message);
    $Message_qp = "";
    while(list(, $Line) = each($MessageLines)) {
        if (strlen($Line) > 75) {
            $Pointer = 0;       
            while ($Pointer <= strlen($Line)) {
                $Offset = 0;
                if (preg_match("/^=(3D|([8-9A-F]{1}[0-9A-F]{1}))$/", substr($Line, ($Pointer+73), 3))) $Offset=-2;
                if (preg_match("/^=(3D|([8-9A-F]{1}[0-9A-F]{1}))$/", substr($Line, ($Pointer+74), 3))) $Offset=-1;
                $Message_qp.= substr($Line, $Pointer, (75+$Offset))."=\n";
                if ((strlen($Line) - ($Pointer+75)) <= 75) {               
                    $Message_qp.= substr($Line, ($Pointer+75+$Offset))."\n";
                    break 1;
                $Pointer+= 75+$Offset;
        } else {
            $Message_qp.= $Line."\n";
    return $Message_qp;
zan at stargeek dot com
25-Jan-2003 01:47
here's the source code to an example of an email contact for that allows your visitors to send you emails from a webpage
thomas at thomak dot de
25-Jan-2003 12:46
I had a problem sending email from UNIX using mail() and having:
ini_set(sendmail_path, "/usr/sbin/sendmail -t -f");

in my PHP-mail program (not in setup).

Receivers server doesn't forward the message.
Now I use "-f " feature as a 5-th parameter in mail():
mail($recEmail,$subject, $message, $headers,"-f");
Now it works well.
Found it on (in German)
works with PHP 4.0.5 upwards (write them).
:-) T.
rune at imptech dot net
21-Dec-2002 06:13
If your using Postfix for SMTP on FreeBSD you MUST end header lines with \n and not \r\n. I'm not sure if this is true of other platforms but this is definitely the case on my FreeBSD server.

-=- RuneImp
ImpTech - Web Design & Hosting
alex at bartl dot net
29-Nov-2002 03:25
This might be some useful stuff to send out emails in either text
or html or multipart version, and attach one or more files or even
none to it. Inspired by Kieran's msg above, I thought it might be
useful to have a complete function for doing this, so it can be used
wherever it's needed. Anyway I am not too sure how this script will
behave under Windows.

{br} represent the HTML-tag for line break and should be replaced,
but I did not know how to not get the original tag  parsed here.

function SendMail($From, $FromName, $To, $ToName, $Subject, $Text, $Html, $AttmFiles)
$From      ... sender mail address like ""
$FromName  ... sender name like "My Name"
$To        ... recipient mail address like ""
$ToName    ... recipients name like "Your Name"
$Subject   ... subject of the mail like "This is my first testmail"
$Text      ... text version of the mail
$Html      ... html version of the mail
$AttmFiles ... array containing the filenames to attach like array("file1","file2")

$TEXT="This is the first test\n in text format\n.";
$HTML="<font color=red>This is the first test in html format.</font>";

    "","PHP Apache Webmailer",         //sender
    "","Recipients Name",     //recipient
    "Testmail",                               //subject
    $TEXT,$HTML,$ATTM);                      //body and attachment(s)
function SendMail($From,$FromName,$To,$ToName,$Subject,$Text,$Html,$AttmFiles){
  or die("neither text nor html part present.");
 $Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail.";
 $From or die("sender address missing");
 $To or die("recipient address missing");
 $headers ="MIME-Version: 1.0\r\n";
 $headers.="From: ".$FromName." <".$From.">\n";
 $headers.="To: ".$ToName." <".$To.">\n";
 $headers.="Reply-To: ".$FromName." <".$From.">\n";
 $headers.="X-Priority: 1\n";
 $headers.="X-MSMail-Priority: High\n";
 $headers.="X-Mailer: My PHP Mailer\n";
 $headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n";

 //Messages start with text/html alternatives in OB
 $Msg ="This is a multi-part message in MIME format.\n";
 $Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";

 //plaintext section
 $Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
 $Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
 // plaintext goes here

 // html section
 $Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
 $Msg.="Content-Transfer-Encoding: base64\n\n";
 // html goes here

 // end of IB

 // attachments
  foreach($AttmFiles as $AttmFile){
   $patharray = explode ("/", $AttmFile);
   $Msg.= "\n--".$OB."\n";
   $Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n";
   $Msg.="Content-Transfer-Encoding: base64\n";
   $Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n";
   //file goes here
   $fd=fopen ($AttmFile, "r");
   fclose ($fd);
 //message ends
 //syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>");
kieran dot huggins at rogers dot com
21-Nov-2002 06:24
Thanks Hilger - that will come in handy on my end.

Here's a great overview of the MIME spec from 1993:

Happy mailing! - Kieran
kieran dot huggins at rogers dot com
07-Nov-2002 01:52
Finally got MIME working with attachments and everything:

The following is an example of a plaintext/html e-mail with attachments

for the HTML code, I had to include the weird markup that outlook express 6 added when the message was sent, otherwise it wouldn't display properly.  Send a copy of the message to yourself and copy the source.

Also, the /n newlines are important, normal rules of HTML seem to go kinda wonky with e-mail...

Experiment with your mailer and try different stuff.


// some local variables
$from_name "Sender Name";
$from_email "";
$to_name "Recipient Name";
$to_email "";
$subject "Fantastic Subject";

// headers need to be in the correct order...
$headers "From: $from_name<$from_email>\n";
$headers .= "Reply-To: <$from_email>\n";
$headers .= "MIME-Version: 1.0\n";
// the following must be one line (post width too small)
$headers .= "Content-Type: multipart/related;
type=\"multipart/alternative\"; boundary=\"----
$headers .= "X-Sender: $from_name<$from_email>\n";
$headers .= "X-Mailer: PHP4\n"//mailer
$headers .= "X-Priority: 3\n"//1 UrgentMessage, 3 Normal
$headers .= "Return-Path: <$from_email>\n";
$headers .= "This is a multi-part message in MIME format.\n";
$headers .= "------=MIME_BOUNDRY_main_message \n";
$headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";

//plaintext section begins
$message "------=MIME_BOUNDRY_message_parts\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";

// your text goes here
$message .= "blah blah -- plaintext version of the message\n";
$message .= "\n";

// html section begins
$message .= "------=MIME_BOUNDRY_message_parts\n";
$message .= "Content-Type: text/html;\n    charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";

// your html goes here -- It didn't appear properly without
// the weird markup that outlook added after sending
$message .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
$message .= "<HTML><BODY>\n";
$message .= "blah blah -- html version of the message\n";

// look ma, I'm referencing an img attachment (see below)
// watch out for weird markup!!!
$message .= "<IMG src=3D\"cid:some_picture\">\n";
$message .= "</BODY></HTML>\n";
$message .= "\n";

// this ends the message part
$message .= "------=MIME_BOUNDRY_message_parts--\n";
$message .= "\n";

// now we add attachments (images, etc)
$message .= "------=MIME_BOUNDRY_main_message\n";
$message .= "Content-Type: image/gif; \n name=\"some_picture.gif\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-ID: <some_picture>\n";
$message .= "\n";
// (truncated for space)
$message .= "R0lGODlheAAZAKIHAMTExCQkJJOTk\n";
$message .= "eLo7wzDKSatVQ5R3u7dDUUjcZ34D\n";
$message .= "\n";
// etc...etc...etc...

//message ends
$message .= "------=MIME_BOUNDRY_main_message--\n";

// send the message :-)


I hope this helps -- sorry for the long post!

Dark_Spirit at beyondinfinit dot com
25-Oct-2002 03:20
I followed an example from Godfried van Loo and found an error in his code. Hotmail was sending my mail to the recipient's junk mail. I found out that if you remove the "To: " line from the header, hotmail sends the mail to the inbox. here is my code:

function SEND_HTML_MAIL($mail_info) {
    $from_name = $mail_info["from_name"];
    $from_address = $mail_info["from_address"];
    $to_name = $mail_info["to_name"];
    $to_address = $mail_info["to_name"]." <".$mail_info["to_address"].">";
    $message = $mail_info["message"];
    $subject = $mail_info["subject"];
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: ".$from_name." <".$from_address.">\r\n";
    $headers .= "Reply-To: ".$from_name." <".$from_address.">\r\n";
    $headers .= "X-Priority: 1\r\n";
    $headers .= "X-MSMail-Priority: High\r\n";
    $headers .= "X-Mailer: iCEx Networks HTML-Mailer v1.0";

    mail($to_address, $subject, $message, $headers);

I hope this code will help you out.

Simon Germain
moacir at uchicago dot edu
23-Oct-2002 05:01
If you're passing variables you got from somewhere else (like a form) into mail(), make sure they're chop()-ped, or else everything will only half-work, causing, at least in one rumoured instance, hours of fretting and scouring of webpages and newsgroups.

It's not the order of the headers, it's not the presence of asterisks in the Subject: line, it's because there are inopportune \ns hiding around
oliver dot ahlberg at smp dot se
20-Oct-2002 12:52
I've found this quite convenient in mail functions distributing various newsletters with HTML content:

function mail_from_file($template) {
$to = "";
$title = "A message";
$header = ""; // Found elsewhere
$message = join('',file($template));


/* PHP Code Body */

This is just a short snippet from my code, and you'll probably want to make some string replacements in the retrieved message templates to personalize the emails for your recipients.
zombie at localm dot org
29-Sep-2002 03:45
Note that in the above example of using sendmail that there must be a new line (\n) before the body starts. I scratched my head for a bit on this one. The messages were sending (even to aol) but the messages were blank, so i added the new line and it worked. The above example is much appriciated, thankyou thankyou.
pvlasenko at hotmail dot com dot com
29-Sep-2002 05:04
If you find your self struggling with mail() function like I was you might want to send mail directly from your mailer and not through the mail() function. I was having hard time sending long(registration confirmation) messages with simple mail() function on Linux. My solution...

// Configuration
$announce_subject = "Message From Our Web Site";
$announce_from_email = "";
$announce_from_name = "Our Site";
$announce_to_email = "";
$body = "Announcement. Our site has a special offer today. Please visit. Thank you.";
$MP = "/usr/sbin/sendmail -t";
$spec_envelope = 1;
// Access Sendmail
// Conditionally match envelope address
$MP .= " -f $announce_from_email";
$fd = popen($MP,"w");
fputs($fd, "To: $announce_to_email\n");
fputs($fd, "From: $announce_from_name <$announce_from_email>\n");
fputs($fd, "Subject: $announce_subject\n");
fputs($fd, "X-Mailer: PHP4\n");
fputs($fd, $body);

Hope this helps you.
Pavel Vlasenko
stevenlim at Edinburgh-Consulting dot com
06-Sep-2002 02:53
How to detect a bounce email

1. make sure the email you send out have the header

2. setup this detect-bounce mail account at your mail server

3. redirect the incoming mail from this email account to your php script (check your mail server doc on how do this)

4. your php script will then be able to process the incoming email in whatever way you like, including to detect bounce mail message (use regexp search).

Note that the mail will be not be store after the mail server has redirect to your script.  If you want to store it, you need additional code in your script

Hope the above help

Steven Lim
IT Consultant (
no dot grstarrett at spam dot cox dot net
20-Aug-2002 02:43
I had a problem with the outgoing email from PHP: The emails were going OUT but not being recieved by SOME users.

Specifically, users with accounts within my own ISP were fine (COX.NET), my .NAME account was OK, and others. AOL users got NOTHING as well as some other users.

The problem was was with PHP.INI settings. Notice the default setting:

sendmail_from = ; for Win32 only

This affects the "return path" header (on my system anyway) REGARDLESS of the From header entry.  Apparently some anti-spam filters look at the return path to see if it is legit and, if not, drop the message.

If you leave this as is it will work fine... for SOME mail transports, but not all!! For it to work properly, I had to configure it to be an email address within the domain of my ISP. Note that I also have the SMTP server set to my ISP's main outgoing SMTP server. Apparently, any address will work as long as it is properly formatted and from the domain of the SMTP server.

My setting now reads similar to:

sendmail_from = ; for Win32 only

I haven't verified it works in all cases, but it works at least for AOL. I'm fairly confident it will work for all my users, I'll try to remember to post more info if I find out anything else.

BTW: I didn't have to change the \r to \r\n with my configuration (XP/IIS5), but I have had trouble with that in other platforms (e.g. NT4/IIS4). You might want to look at that as well.
redy dot r at NOSPAMmadagascan dot com
17-Aug-2002 06:46
If you need to send an e-mail with an html content and the same e-mail have Bcc headers.
Place the Bcc (and why not also Cc) at the end of your additional headers. Otherwise, people receiving the email in copy may have the html code in their screen. The one who are designed as main recipient will not have this problem.

Explanation :
The e-mail headers are broken when the PHP parser delete the Bcc line (Removed cause hidden, obvious !).

Example :

This is bad

    $header    = "From: \"".addslashes($sender_name)."\" <".$sender_email.">\r\n";
    $header   .= "Reply-To: ".$sender_email."\r\n";
    $header   .= "Cc: ".$other_email."\r\n";
    $header   .= "Bcc: ".$another_email."\r\n";
    $header   .= "MIME-Version: 1.0\r\n";
    $header   .= "Content-Type: text/html; charset=iso-8859-1\r\n";
    $header   .= "X-Priority: 1\r\n";
    $header   .= "X-Mailer: PHP / ".phpversion()."\r\n";

The following is good

    $header    = "From: \"".addslashes($sender_name)."\" <".$sender_email.">\r\n";
    $header   .= "Reply-To: ".$sender_email."\r\n";
    $header   .= "MIME-Version: 1.0\r\n";
    $header   .= "Content-Type: text/html; charset=iso-8859-1\r\n";
    $header   .= "X-Priority: 1\r\n";
    $header   .= "X-Mailer: PHP / ".phpversion()."\r\n";
    $header   .= "Cc: ".$other_email."\r\n";
    $header   .= "Bcc: ".$another_email."\r\n";

Sorry for my bad english. :-)

Redy Ramamonjisoa
mjt at jpeto dot net
26-Jun-2002 10:08
If some of your mails cannot be received by some people, you might have the following problem:

Some mailservers block messages with more than 1024 Characters in a single line.

Solution: just add a simple linebreak (\n) after the last space before each character 1024

You could possibly use wordwrap() for this...
sergiopaternoster at tiscali dot it
12-Jun-2002 11:07
If you have downloaded an email via POP connection, ex.:
$complete_email ="
Date: Wed, 20 Jun 2001 20:18:47 -0400
From: "Sergio Paternoster" <>
To: "My Users" <>
Subject: Hello from Sergio!
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello from Sergio!
and want to forward it to another email address, just change the To: field into the encoded downloaded email and then use

mail("", "", "",$To_changed_complete_email);
aharradine at skychannel dot com dot au
06-Jun-2002 10:50
use these headers to send in html form

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
12-Apr-2002 10:35
As noted above sendmail_from is only used on MS Windows, to change the default sender on unix you must add -f to sendmail_path. For example in a <VirtualHost> directive:
php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f"

would set the default return-path for mail from that virtual host.
drtebi at yahoo dot com
03-Apr-2002 12:58
Hi there,
here is a little snippet that can be used in your mail script in order to check if the mail was really sent from the domain the message originated from:

// array for allowed domains (lower case please)
$referers = array('', '', '');

// add upper case referrers
$size = sizeof($referers);
for($i = 0; $i < $size; $i++){
  $referers[] = strtoupper($referers[$i]);

// check referers
for($i = 0; $i < sizeof($referers); $i++){
  if(substr($HTTP_SERVER_VARS['HTTP_REFERER'], 7, strlen($referers[$i])) == $referers[$i]){
    $bad_referer = FALSE;
    $bad_referer = TRUE;

I added the upper case domains, since once in a while surfers tend to write in all-caps.

Hope that helps someone :-)


 Last updated: Thu, 21 Aug 2003
show source | credits | sitemap | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat 01 Nov 2003 04:13:36 EST EST