note 74873 modified in ref.mail by danbrown

From: Date: Sun, 17 May 2009 20:08:35 +0000
Subject: note 74873 modified in ref.mail by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155340@lists.php.net to get a copy of this message
Here is a PHP Mail Multipart/Alternative (Plain Text and HTML) code for *nix servers (Unix Like Servers)... if you are hosted on a windows server, simply replace all "\n" or "\n\n" in the below code to "\r\n" or "\r\n\r\n" respectively. This code is for anyone who has already written an HTML page for their PHP mail... there are several PHP > HTML free translators on the internet. You may use one of them to translate your HTML code to PHP to insert into the following code. All there needs to change is to place a backslash before any quotations (EX: ... confirm that \"Our Company\" has ...), and to end each line with a newline character (EX: \n )... This code method has been successfully tested with Apple Mail, Microsoft Outlook, G-Mail, and Yahoo Mail. I hope this helps out anyone that is writing a multipart/alternative PHP mailer script. <?php # -=-=-=- PHP FORM VARIABLES (add as many as you would like) $name = $_POST["name"]; $email = $_POST["email"]; $invoicetotal = $_POST["invoicetotal"]; # -=-=-=- MIME BOUNDARY $mime_boundary = "----Your_Company_Name----".md5(time()); # -=-=-=- MAIL HEADERS $to = "$email"; $subject = "This text will display in the email's Subject Field"; $headers = "From: Our Company <company@ourcompany.com>\n"; $headers .= "Reply-To: Our Company <company@ourcompany.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; # -=-=-=- TEXT EMAIL PART $message = "--$mime_boundary\n"; $message .= "Content-Type: text/plain; charset=UTF-8\n"; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= "$name:\n\n"; $message .= "This email is to confirm that \"Our Company\" has received your order.\n"; $message .= "Please send payment of $invoicetotal to our company address.\n\n"; $message .= "Thank You.\n\n"; # -=-=-=- HTML EMAIL PART $message .= "--$mime_boundary\n"; $message .= "Content-Type: text/html; charset=UTF-8\n"; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= "<html>\n"; $message .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:14px; color:#666666;\">\n"; $message .= "$name:<br>\n"; $message .= "<br>\n"; $message .= "This email is to confirm that \"Our Company\" has received your order.<br>\n"; $message .= "Please send payment of $invoicetotal to our company address.<br>\n\n"; $message .= "<br>\n"; $message .= "Thank You.<br>\n\n"; $message .= "</body>\n"; $message .= "</html>\n"; # -=-=-=- FINAL BOUNDARY $message .= "--$mime_boundary--\n\n"; # -=-=-=- SEND MAIL $mail_sent = @mail( $to, $subject, $message, $headers ); echo $mail_sent ? "Mail sent" : "Mail failed"; ?> --was-- Here is a PHP Mail Multipart/Alternative (Plain Text and HTML) code for *nix servers (Unix Like Servers)... if you are hosted on a windows server, simply replace all "\n" or "\n\n" in the below code to "\r\n" or "\r\n\r\n" respectively. This code is for anyone who has already written an HTML page for their PHP mail... there are several PHP > HTML free translators on the internet. You may use one of them to translate your HTML code to PHP to insert into the following code. All there needs to change is to place a backslash before any quotations (EX: ... confirm that \"Our Company\" has ...), and to end each line with a newline character (EX: \n )... This code method has been successfully tested with Apple Mail, Microsoft Outlook, G-Mail, and Yahoo Mail. I hope this helps out anyone that is writing a multipart/alternative PHP mailer script. <?php # -=-=-=- PHP FORM VARIABLES (add as many as you would like) $name = $_POST["name"]; $email = $_POST["email"]; $invoicetotal = $_POST["invoicetotal"]; # -=-=-=- MIME BOUNDARY $mime_boundary = "----Your_Company_Name----".md5(time()); # -=-=-=- MAIL HEADERS $to = "$email"; $subject = "This text will display in the email's Subject Field"; $headers = "From: Our Company <company@ourcompany.com>\n"; $headers .= "Reply-To: Our Company <company@ourcompany.com>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; # -=-=-=- TEXT EMAIL PART $message = "--$mime_boundary\n"; $message .= "Content-Type: text/plain; charset=UTF-8\n"; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= "$name:\n\n"; $message .= "This email is to confirm that \"Our Company\" has received your order.\n"; $message .= "Please send payment of $invoicetotal to our company address.\n\n"; $message .= "Thank You.\n\n"; # -=-=-=- HTML EMAIL PART $message .= "--$mime_boundary\n"; $message .= "Content-Type: text/html; charset=UTF-8\n"; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= "<html>\n"; $message .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:14px; color:#666666;\">\n"; $message .= "$name:<br>\n"; $message .= "<br>\n"; $message .= "This email is to confirm that \"Our Company\" has received your order.<br>\n"; $message .= "Please send payment of $invoicetotal to our company address.<br>\n\n"; $message .= "<br>\n"; $message .= "Thank You.<br>\n\n"; $message .= "</body>\n"; $message .= "</html>\n"; # -=-=-=- FINAL BOUNDARY $message .= "--$mime_boundary--\n\n"; # -=-=-=- SEND MAIL $mail_sent = @mail( $to, $subject, $message, $headers ); echo $mail_sent ? "Mail sent" : "Mail failed"; ?> http://php.net/manual/en/ref.mail.php

« previous php.notes (#155340) next »