Sending HTML email from PHP -
I am trying to send a simple HTML email from PHP. The following is the result of Gmail's empty e-mail in the code below. There is also an empty attachment called 'Anime', which is what I want; Although this may not be a sign of working.
The code I'm using is:
& lt ;? Php // email receiver $$ = 'Morrillkevin@gmail.com'; // Set the topic of email $ subject = 'Test HTML Email'; // Create a boundary string It should be unique / so we use the MD5 algorithm to generate a random hash $ random_hash = md5 (date ('r', time ()); // we want to pass the header Note that they have been separated with \ r \ n $ headers = "From: webmaster@example.com \ r \ n Reply-to: webmaster@example.com"; // add threshold string and mime Type specification $ header. = "\ R \ n Content-type: multipart / optional; border = \" PHP-alt-". $ Random_hash. "\" "; // Define body of message ob_start (); // Turn on output buffering? & Gt; - PHP- alt- & lt ;? Php echo $ random_hash;? & Gt; Mime-version : 1.0 Content-Type: Text / plain; Charset = "ISO-885 9-1" Content-Transfer-Encoding: 7 Bit Hello World !!! This is a simple text email message - PHP- alt- & lt ;? php echo $ Random_hash;? & Gt; MIME-version: 1.0 Content-Type: Text / html; Charset = "iso-8859-1" Content-Transfer-Encoding: 7bit & lt; h2 & gt; Hello World! & Lt; / h2 & Gt; & lt; p & gt; This & lt; B & gt; HTML & lt; / B & gt; There is something with formatting. & Lt; / P & gt; --php- alt- & lt ;? Php echo $ random_hash; ? & Gt; - & lt;? // Copy the current buffer content into the $ message variable and delete the current output buffer $ message = ob_get_clean (); // email $ mail_sent = @mail ($ $, $ theme, $ message, $ header); // If the message is successfully printed "mail sent" Otherwise echo "Mail failed" $ mail_sent? "Sent Mail": "Mail Failed";
Use class if possible. This will make your work very simple.
Comments
Post a Comment