Posted By

acosonic on 08/28/09


Tagged

email php popen fputs


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


Sending multipart/alternative (text and html both together) email messages from PHP directly via sendmail


 / Published in: PHP
 

sendmail needs to be working and configured properly

uses popen and fputs

  1. $random_hash = md5(date('r', time()));
  2.  
  3. $message=<<<EOL
  4. --frontier
  5. Content-type: text/plain; charset=UTF-8
  6. Content-Transfer-Encoding: 7bit
  7.  
  8. Poštovanje,
  9.  
  10. uspešno ste kreirali novi nalog na aplikaciji
  11.  
  12. Vaše korisni�ko ime: $username
  13. Å ifra: $p_sifra
  14. Molimo vas da sa�uvate ove podatke, kako bi ih ubudu�e bez problema koristili.
  15.  
  16. Pristup aplikaciji je mogu� putem:
  17. $http_path
  18. --frontier
  19. Content-Type: text/html; charset=UTF-8
  20. Content-Transfer-Encoding: 7bit
  21.  
  22. <html>
  23. <head>
  24. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  25. </head>
  26. <body>
  27. <h2>Poštovanje, </h2>
  28. <p>
  29. uspešno ste kreirali novi nalog na aplikaciji
  30. </p>
  31. Vaše korisni�ko ime: $username<br/>
  32. Å ifra: $p_sifra<br/><br/>
  33. Molimo vas da sa�uvate ove podatke, kako bi ih ubudu�e bez problema koristili.<br/>
  34. <br/>
  35. Pristup aplikaciji je mogu� putem:<br/>
  36. $http_path
  37. </body>
  38. </html>
  39. --frontier--
  40. EOL;
  41.  
  42. print $message;
  43.  
  44.  
  45. $fd = popen("sendmail -t","w") or die("Couldn't Open Sendmail");
  46.  
  47. fputs($fd, "To: [email protected] \n");
  48. fputs($fd, "From: \"Your App\" <[email protected]> \n");
  49. fputs($fd, "Subject: Test message from my web site \n");
  50.  
  51. fputs($fd,"MIME-Version: 1.0\n");
  52. fputs($fd,"Content-type: multipart/alternative; boundary=\"frontier\"\n\n");
  53. fputs($fd,"This is a message with multiple parts in MIME format.\n");
  54.  
  55. fputs($fd, $message);
  56. pclose($fd);

Report this snippet  

You need to login to post a comment.