HTML Emails with wp_mail()


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1.  
  2.  
  3. 1 <?php
  4. 2 function mail_from() {
  5. 3 $emailaddress = '[email protected]';
  6. 4 return $emailaddress;
  7. 5 }
  8. 6
  9. 7 function mail_from_name() {
  10. 8 $sendername = "1stWebDesigner.com - Dainis";
  11. 9 return $sendername;
  12. 10 }
  13. 11
  14. 12 add_filter('wp_mail_from','mail_from');
  15. 13 add_filter('wp_mail_from_name','mail_from_name');
  16. 14 ?>
  17. 1 <html></span></h2>
  18. 2 <pre><head>
  19. 3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. 4 </head>
  21. 5 <body>
  22. 6 <table style="font-family: Verdana,sans-serif; font-size: 11px; color: #374953; width: 600px;">
  23. 7 <tr>
  24. 8 <td align="left"><a href="<?php bloginfo('url'); ?>" title="MyBlog"><img src="<?php bloginfo('url'); ?>/logo.png" alt="MyBlog" style="border: none;" ></a></td>
  25. 9 </tr>
  26. 10 <tr>
  27. 11 <td>&nbsp;</td>
  28. 12 </tr>
  29. 13 <tr>
  30. 14 <td align="left">Yo, <?php echo $name; ?>.<br />How are you?</td>
  31. 15 </tr>
  32. 16 <tr>
  33. 17 <td>&nbsp;</td>
  34. 18 </tr>
  35. 19 <tr>
  36. 20 <td>I've recieved your message and we'll answer it soon!</td>
  37. 21 </tr>
  38. 22 <tr>
  39. 23 <td>&nbsp;</td>
  40. 24 </tr>
  41. 25 <tr>
  42. 26 <td align="left" style="background-color: #aeaeae; color:#FFF; font-size: 12px; font-weight: bold; padding: 0.5em 1em;">Original Message</td>
  43. 27 </tr>
  44. 28 <tr>
  45. 29 <td><?php echo $message; ?></td>
  46. 30 </tr>
  47. 31 <tr>
  48. 32 <td>&nbsp;</td>
  49. 33 </tr>
  50. 34 <tr>
  51. 35 <td align="center" style="font-size: 10px; border-top: 1px solid #c10000;">
  52. 36 <p><i>Thank you!</i><br /><b>MyBlog</b> - <br /><?php bloginfo('url'); ?></p>
  53. 37 </td>
  54. 38 </tr>
  55. 39 </table>
  56. 40 </body>
  57. 41 </html>
  58.  
  59. And we call this function with our contact form:
  60. 1 <?php
  61. 2 function contactMail($post) {
  62. 3 $attachments = "";
  63. 4 $subject = "[MyBlog] Contact";
  64. 5 $name = $post["name"];
  65. 6 $email = $post["email"];
  66. 7 $message = $post["message"];
  67. 9 include(TEMPLATEPATH . '/_mails/contact.html');
  68. 10 $message = ob_get_contents();
  69. 12
  70. 13 $headers = "From: [email protected]
  71. ";
  72. 14 $headers .= "Return-Path: [email protected]
  73. ";
  74. 15 $headers .= "MIME-Version: 1.0
  75. ";
  76. 16 $headers .= "Content-Type: text/html; charset=UTF-8
  77. ";
  78. 17 $headers .= "BCC: [email protected]
  79. ";
  80. 18 //$headers .= "BCC: [email protected]
  81. ";
  82. 19 wp_mail( $email, $subject, $message, $headers, $attachments );
  83. 20 }
  84. 21 ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.