note 75955 deleted from function.mail by danbrown

From: Date: Sat, 25 Apr 2009 14:59:18 +0000
Subject: note 75955 deleted from function.mail by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153735@lists.php.net to get a copy of this message
Note Submitter: bsaul at inwind dot it ---- 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); }

« previous php.notes (#153735) next »