/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php //define the receiver of the email //define the subject of the email $subject = 'Test HTML email'; // Generate a random boundary string // Using the heredoc syntax to declare the headers $headers = <<<HEADERS From: Test <[email protected]> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="PHP-alt$mime_boundary" HEADERS; // Use our boundary string to create plain text and HTML versions $message = <<<MESSAGE --PHP-alt$mime_boundary Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit This Is a Plain Text Email This message has no HTML. http://w3schools.com --PHP-alt$mime_boundary Content-type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 7bit <html> <body> <h1>This Is an HTML Email</h1> <p> This message is composed in <a href="http://w3schools.com">HTML</a>. </p> </body> </html> --PHP-alt$mime_boundary-- MESSAGE; // Send the message { // If the mail function fails, return an error message echo "Something went wrong!"; } else { // Return a success message if nothing went wrong echo "Message sent successfully. Check your email!"; } ?>