note 79365 deleted from function.mail by ezyang

From: Date: Fri, 23 Nov 2007 16:07:19 +0000
Subject: note 79365 deleted from function.mail by ezyang
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-132511@lists.php.net to get a copy of this message
Note Submitter: Narthollis Reason: bad code ---- Just put together a nice little function to convert from html formated text to plain text from mailing. Possible uses are for mailing from forms that use WYSIWYG editors. <?php function plainTextMail($to,$subject,$message,$headers=null,$paramiters=null) { /* We convert line breaks and the end of block elements to new lines */ $openTagsLB = array(); $closeTagsLB = array('p','div'); $singleTagsLB = array('br'); foreach($openTagsLB as $break) { $message = eregi_replace( '<[:blank:]*'.$break.'[:blank:]*>', "/n", $message ); } foreach($closeTagsLB as $break) { $message = eregi_replace( '<[:blank:]*/'.$break.'[:blank:]*>', "/n", $message ); } foreach($singleTagsLB as $break) { $message = eregi_replace( '<[:blank:]*'.$break.'[:blank:]*/[:blank:]*>', "/n", $message ); } /* Remove &nbsp; rather than replace it as it genearly causes message issues in the resulting plaintext */ $message = str_replace('&nbsp;',$message); /* Strip html tags, replace html entities with there literals, trim excess whitespace from the start and end of the message and then wordwrap each line to 70 characters and finaly send the message */ $message = strip_tags($message); $message = html_entity_decode($message); $message = trim($message); $message = wordwrap($message,70); mail($to,$subject,$message,$headers,$paramiters); } ?>

« previous php.notes (#132511) next »