SoFunction
Updated on 2025-04-08

Another solution for MAIL under PHP

Some time ago, I came into contact with DEC Tru64 Unix. I installed PHP+APACHE on it. I can use the provided mail function to never send messages normally. So I wrote a function that uses the pipeline under UNIX and the SOCK function of PHP to send messages. After experimenting, I succeeded. The following is the original code of this function.
function mymail($mto,$mcc,$msubject,$mbody)
{  
$from="webmaster@";
$sign = "\n";//what you can write
$sendmailpath="/usr/lib/sendmail";//Semdmail path
$bound = "===========_".uniqid("BCFMail")."==_";//District character
  $headers =  "MIME-Version: 1.0\n".
            "Content-Type: multipart/mixed; boundary=\"$bound\"\n".
            "Date: ".date("D, d M H:i:s Y ")."\n".
            "From: $from\n".
            "To: $mto\n".
            "Cc: $mcc\n".
            "Subject: $msubject\n".
            "Status: \n".
            "X-Status:\n".
            "X-Mailer: MY Email Interface\n".
            "X-Keywords:\n\n";
  $content="--".$bound."\n"."Content-Type:text/plain;charset=\"GB2312\"\n\n".$mbody.$sign."\n";
  $end = "\n"."--".$bound."--\n";
  $sock = popen("$sendmailpath -t -f 'webmaster@'",'w');
  fputs($sock, $headers);
  fputs($sock, $content);
  fputs($sock, $end);
  fputs($sock, ".\n");
  fputs($sock, "QUIT\n");
  pclose($sock);