[PHP] php发送邮件函数,支持html和普通文本 →→→→→进入此内容的聊天室

来自 , 2019-04-13, 写在 PHP, 查看 120 次.
URL http://www.code666.cn/view/8c9a14ff
  1. <?php
  2. function send_mail($emailaddress, $fromaddress, $namefrom, $emailsubject, $body)
  3. {
  4.   $eol="\n";
  5.   $mime_boundary=md5(time());
  6.  
  7.   # Common Headers
  8.  $headers .= "From: $namefrom <$fromaddress>".$eol;
  9.   $headers .= "Reply-To: $namefrom <$fromaddress>".$eol;
  10.   $headers .= "Return-Path: $namefrom <$fromaddress>".$eol;
  11.             // these two to set reply address
  12.  $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
  13.  $headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters
  14.  
  15.   # Boundry for marking the split & Multitype Headers
  16.  $headers .= 'MIME-Version: 1.0'.$eol;
  17.   $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
  18.  
  19.   $msg = "";    
  20.  
  21.   # Setup for text OR html
  22.  $msg .= "Content-Type: multipart/alternative".$eol;
  23.  
  24.   # Text Version
  25.  $msg .= "--".$mime_boundary.$eol;
  26.   $msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
  27.   $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  28.   $msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
  29.  
  30.   # HTML Version
  31.  $msg .= "--".$mime_boundary.$eol;
  32.   $msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
  33.   $msg .= "Content-Transfer-Encoding: 8bit".$eol;
  34.   $msg .= $body.$eol.$eol;
  35.  
  36.   # Finished
  37.  $msg .= "--".$mime_boundary."--".$eol.$eol;  // finish with two eol's for better security. see Injection.
  38.  
  39.   # SEND THE EMAIL
  40. // ini_set(sendmail_from,$fromaddress);  // the INI lines are to force the From Address to be used !
  41.   mail($emailaddress, $emailsubject, $msg, $headers);
  42.  
  43. //  ini_restore(sendmail_from);
  44. //  echo "mail send";
  45.     return 1;
  46. }
  47.  
  48. ?>
  49.  

回复 "php发送邮件函数,支持html和普通文本"

这儿你可以回复上面这条便签

captcha