note 17117 added to function.mail

From: Date: Tue, 27 Nov 2001 04:50:03 +0000
Subject: note 17117 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-21308@lists.php.net to get a copy of this message
Developers might need to be a bit cautious in filling out the first argument of the mail() function. <br><br>It accepts comma delimited email addresses but if an embedded "\r\n" is in the string it invariably discards the remainder of the string and treats it as part of the message and the "subject" and "additional headers" will be treated as part of the message as well. <br><br>I got this observation based on a mailer application I developed that reads off from an external file a list of recipient name and email addresses and goes through the list for sending newsletter updates. <br><br>After stripping the email address of the "\r\n" entries, the program worked fine. Before that, the subject mysteriously disappears and the body of the message contained both the subject and any additional headers I submitted. <br><br>The general construct is as follows: $recipientmail = str_replace("\r","",$recipientmail); $recipientmail = str_replace("\n","",$recipientmail); if (mail($recipientmail, "Whatever Subject Here", $mailbody, "From: $senderemail","-f $senderemail")) { //succeeded sending mail, do what you have to do } else { //failed sending mail.... } <br><br>Do note that the mail() instance in this case uses the fifth optional parameter which only works for PHP4.0.5 upwards. Remove in lower versions as required. -- http://www.php.net/manual/en/function.mail.php http://master.php.net/manage/user-notes.php?action=edit+17117 http://master.php.net/manage/user-notes.php?action=delete+17117 http://master.php.net/manage/user-notes.php?action=reject+17117

« previous php.notes (#21308) next »