note 89169 added to function.mail

From: Date: Wed, 25 Feb 2009 03:06:49 +0000
Subject: note 89169 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-151093@lists.php.net to get a copy of this message
As some SMTP servers (for example Argosoft Mail Server for Windows) may lead into troubles when sending a mail to "Full Name <user@domain.tld>" instead of simply "user@domain.tld", the following may be a solution: <?php $Result = trim(preg_replace("/([\w\s]+)<([\S@._-]*)>/", " $2", $Input)); ?> I'm not a PCRE guru, but this seems to work pretty good with any number of e-mail addresses, even when the $Input contains "mixed" address definitions (ie. some with Full Name and some without). Examples: Input: "User 1 <user1@foo.tld>, User 2 <user2@foo.tld>, user3@foo.tld" Result: "user1@foo.tld, user2@foo.tld, user3@foo.tld"; Input: "user1@foo.tld, user2@foo.tld" Result: "user1@foo.tld, user2@foo.tld" The use of trim is optional, just to keep a nice space after the comma separator. If you don't mind about showing nice recipient lists to the MTA, I think this would work as well: <?php $Result = preg_replace("/([\w\s]+)<([\S@._-]*)>/", "$2", $Input); ?> Anyway I hope that someone could improve these expressions. :) ---- Server IP: 213.92.11.19 Probable Submitter: 82.53.9.215 ---- Manual Page -- http://www.php.net/manual/en/function.mail.php Edit -- https://master.php.net/note/edit/89169 Del: integrated -- https://master.php.net/note/delete/89169/integrated Del: useless -- https://master.php.net/note/delete/89169/useless Del: bad code -- https://master.php.net/note/delete/89169/bad+code Del: spam -- https://master.php.net/note/delete/89169/spam Del: non-english -- https://master.php.net/note/delete/89169/non-english Del: in docs -- https://master.php.net/note/delete/89169/in+docs Del: other reasons-- https://master.php.net/note/delete/89169 Reject -- https://master.php.net/note/reject/89169 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151093) next »