note 24292 added to function.mail

From: Date: Mon, 12 Aug 2002 14:42:48 +0000
Subject: note 24292 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-34873@lists.php.net to get a copy of this message
I recently had to spend a lot of time finetuning a function for mail() which would work properly on both Linux and Win32 server. Here's the wrapper function, which should solve all (or most) of the common problems that beginners run into: function send_mail($myname, $myemail, $contactname, $contactemail, $subject, $message) { $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1\n"; $headers .= "X-Priority: 1\n"; $headers .= "X-MSMail-Priority: High\n"; $headers .= "X-Mailer: php\n"; $headers .= "From: \"".$myname."\" <".$myemail.">\n"; return(mail("\"".$contactname."\" <".$contactemail.">", $subject, $message, $headers)); } This has been tested with both Linux (qmail) and Win32 (ezmts) mail servers, and worked perfectly well. Note that the two headers "X-Priority" and "X-MSMail-Priority", can be left out - but they will help overcome some of the more aggressive spam filtering systems (hotmail, yahoo mail, ...) and ensures your mail is delivered. Also note that you should use \n for new lines in the body of your message - not \r or \r\n ... these don't work on all mail servers, but apparently \n does. Finally, here's an example of using the function, sending an email from "the company" to "the customer": if (send_mail("Company", "person@company.com", "Customer", "customer@server.com", "This is a test", "This is a test\nOne two three four\nBlah blah blah\nThis is a test!")) { print "SENT!"; } else { print "FAILED!"; } -- http://www.php.net/manual/en/function.mail.php http://master.php.net/manage/user-notes.php?action=edit+24292 http://master.php.net/manage/user-notes.php?action=delete+24292 http://master.php.net/manage/user-notes.php?action=reject+24292

« previous php.notes (#34873) next »