note 75955 added to function.mail
| From: | bsaul at inwind dot it | Date: | Sat, 23 Jun 2007 21:19:00 +0000 |
| Subject: | note 75955 added to function.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127904@lists.php.net to get a copy of this message | ||
First excuse me for bad english. I'm working on a function that send html or text or both,
e-mail message. I try all the example but no one working on my system (windows XP with PostCast SMTP
server). Finally i try this and work. I hope your find useful:
function mailTo ($from, $to, $oggetto, $contenuto, $type = "both", $reply = true) {
// If $contenuto == file reading
$messaggio = @file_get_contents( $content, 1);
if ($messaggio) { $contenuto = $messaggio; }
$messaggio = '';
// Standar Header
$crlf = chr(10) . chr(13);
$intestazione = "To: {$to}" . $crlf;
$intestazione .= "From: {$from}" . $crlf;
$intestazione .= "Return-Path: " . (($reply)? $from : substr_replace($from,
"noreply", 0, strpos($from, '@'))) . $crlf;
$intestazione .= 'Reply-To: ' .(($reply)? $from : substr_replace($from,
"noreply", 0, strpos($from, '@'))) . $crlf;
$intestazione .= 'X-Mailer: PHP/' . phpversion() . $crlf;
// MIME boundary
$separatore = 'PHP' . md5(uniqid(time()));
// MIME Header
$intestazione .= 'MIME-Version: 1.0' . $crlf;
switch ($type){
case 'html' :
// Header for client non MIME compatible
$intestazione .= 'Content-Type: text/html; charset=ISO-8859-15' . $crlf;
$intestazione .= 'Content-Transfer-Encoding: 7bit' . $crlf;
$messaggio .= "\n{$contenuto}\n";
break;
case 'both' :
$intestazione .= "Content-Type: multipart/alternative;\n\tboundary=\"" .
$separatore . '"' . $crlf;
// Create message for no mime client
$messaggio .= "For English People: This is a multi-part message in MIME format.\nIf you are
reading this, consider upgrading your e-mail client to a MIME-compatible client.\n";
$messaggio .= "For Italian People: Questo è un messaggio MIME.\nSe si stà leggendo
questa nota, consigliamo l\'aggiornamento del programma di posta elettronica con uno
compatibile MIME";
$messaggio .= "\n--{$separatore}\n";
$messaggio .= "Content-Type: text/plain; charset=ISO-8859-15\n";
$messaggio .= "Content-Transfer-Encoding: 7bit\n\n";
case 'text' :
$messaggio .= strip_tags($contenuto);
if ($type == 'both') {
$messaggio .= "\n--{$separatore}\n";;
$messaggio .= "Content-Type: text/html; charset=ISO-8859-15\n";
$messaggio .= "Content-Transfer-Encoding: 7bit\n";
$messaggio .= "\n{$contenuto}";
$messaggio .= "\n--{$separatore}\n";
}
}
// Send MAIL
return mail($to, $oggetto, $messaggio, $intestazione);
}
----
Server IP: 213.92.11.19
Probable Submitter: 62.10.93.74
----
Manual Page -- http://www.php.net/manual/en/function.mail.php
Edit -- https://master.php.net/note/edit/75955
Del: integrated -- https://master.php.net/note/delete/75955/integrated
Del: useless -- https://master.php.net/note/delete/75955/useless
Del: bad code -- https://master.php.net/note/delete/75955/bad+code
Del: spam -- https://master.php.net/note/delete/75955/spam
Del: non-english -- https://master.php.net/note/delete/75955/non-english
Del: in docs -- https://master.php.net/note/delete/75955/in+docs
Del: other reasons-- https://master.php.net/note/delete/75955
Reject -- https://master.php.net/note/reject/75955
Search -- https://master.php.net/manage/user-notes.php