Juno_okyo

Send html emails in php using the mail function

Jan 27th, 2015
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2. // Source: http://www.binarytides.com/send-html-emails-php-mail-function/
  3.  
  4. function html_mail($to, $subject, $message, $options)
  5. {
  6.     if(isset($options['from_name']))
  7.     {
  8.         $headers = "From: " . $options['from_name'] . "<".$options['from_email'].">" . "rn";
  9.     }
  10.     $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "rn";
  11.     //$headers .= "CC: someone@example.comrn";
  12.     $headers .= "MIME-Version: 1.0rn";
  13.     $headers .= "Content-Type: text/html; charset=ISO-8859-1rn";
  14.      
  15.     mail($to, $subject, $message, $headers);
  16. }
  17.  
  18. $to = 'm00n.silv3r@gmail.com';
  19. $subject = 'Welcome to website';
  20. $from_name = 'Sunny';
  21. $from_email = 'no-reply@example.com';
  22.  
  23. $message = '<html><body>';
  24. $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
  25. $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>Silver Moon</td></tr>";
  26. $message .= "<tr><td><strong>Email:</strong> </td><td>m00n.silv3r@gmail.com</td></tr>";
  27. $message .= "<tr><td><strong>Location:</strong> </td><td>Moon</td></tr>";
  28. $message .= "</table>";
  29. $message .= "</body></html>";
  30.  
  31. html_mail($to, $subject, $message, array('from_email' => $from_email, 'from_name' => $from_name));
Add Comment
Please, Sign In to add comment