note 79365 added to function.mail
| From: | Narthollis at osu1 dot php dot net | Date: | Fri, 23 Nov 2007 00:33:50 +0000 |
| Subject: | note 79365 added to function.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132498@lists.php.net to get a copy of this message | ||
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 rather than replace it as it genearly causes
message issues in the resulting plaintext */
$message = str_replace(' ',$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);
}
?>
----
Server IP: 203.202.10.60
Probable Submitter: 150.101.52.252
----
Manual Page -- http://www.php.net/manual/en/function.mail.php
Edit -- https://master.php.net/note/edit/79365
Del: integrated -- https://master.php.net/note/delete/79365/integrated
Del: useless -- https://master.php.net/note/delete/79365/useless
Del: bad code -- https://master.php.net/note/delete/79365/bad+code
Del: spam -- https://master.php.net/note/delete/79365/spam
Del: non-english -- https://master.php.net/note/delete/79365/non-english
Del: in docs -- https://master.php.net/note/delete/79365/in+docs
Del: other reasons-- https://master.php.net/note/delete/79365
Reject -- https://master.php.net/note/reject/79365
Search -- https://master.php.net/manage/user-notes.php