通过sen直接从PHP发送多部分/可选(文本和html一起)电子邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过sen直接从PHP发送多部分/可选(文本和html一起)电子邮件相关的知识,希望对你有一定的参考价值。

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] ");
  48. fputs($fd, "From: "Your App" <[email protected]> ");
  49. fputs($fd, "Subject: Test message from my web site ");
  50.  
  51. fputs($fd,"MIME-Version: 1.0 ");
  52. fputs($fd,"Content-type: multipart/alternative; boundary="frontier" ");
  53. fputs($fd,"This is a message with multiple parts in MIME format. ");
  54.  
  55. fputs($fd, $message);
  56. pclose($fd);

以上是关于通过sen直接从PHP发送多部分/可选(文本和html一起)电子邮件的主要内容,如果未能解决你的问题,请参考以下文章

通过电子邮件发送 HTML 表单

如何使用 web api 将图像和文本从 android 应用程序发送到 sql server

通过 PHP 使用 HTTP POST 发送 XML 数据

仅发送纯文本电子邮件,正文中包含 Rails mime 部分

Azure Blob PHP SDK - 直接从自定义多部分 API 请求上传到 Azure 存储

使用 AJAX + 多部分表单数据 + UTF-8 编码发送文件和文本