Browsing articles from "September, 2009"

Sending HTML mail by mail()

Sep 17, 2009   //   by nuhil   //   Featured, HTML, PHP, Tips for the New  //  No Comments
<?php
  1. $to = "nuhilmehdy@gmail.com";
  2. $subject = "HTML Test";
  3. $Name = "Nuhil"; //senders name. // This is just for display name
  4. $email = "email@adress.com"; //senders e-mail adress. // I think this would be generated by the host automatically
  5. $last_name = "Mehdy"; // A test variable for using in the html format
  6.  
  7. $message = '
  8. <html>
  9. <head>
  10. <title>HTML email</title>
  11. </head>
  12. <body>
  13. <p>This email contains HTML Tags!</p>
  14. <table width="100%"  border="1">
  15.  <tr>
  16.    <td>First Name </td>
  17.    <td>Last Name </td>
  18.  </tr>
  19.  <tr>
  20.    <td>Nuhil</td>
  21.    <td>'.$last_name.'</td>
  22.  </tr>
  23. </table>
  24. </body>
  25. </html>
  26. '; // Use ' (single quote) for defining the variable content if you use " (double quote) inside that html format OR use reverse method
  27.  
  28. $headers = "MIME-Version: 1.0" . "\r\n"; // Always set content-type when sending HTML email
  29. $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // This defines the mail as html content
  30.  
  31. // More headers
  32. $headers .= "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
  33. $headers .= "Cc: nuhil@yahoo.com" . "\r\n"; // For Cc sending you can use headers also
  34.  
  35. mail($to,$subject,$message,$headers);
  36. ?>