Home > Article > Backend Development > Another solution to MAIL under PHP_PHP Tutorial
Some time ago, I came into contact with DEC Tru64 Unix. I installed PHP+APACHE on it. I could use the provided mail function but could not send mail normally, so I wrote a function myself, which uses the pipe under UNIX and the SOCK function of PHP to send mail. Xin, the experiment was non-resident and successful. The following is the original code of this function.
function mymail($mto,$mcc,$msubject,$mbody)
{
$from="webmaster@backhome.com.cn";
$sign = "n";// Write whatever you want
$sendmailpath="/usr/lib/sendmail";//Semdmail path
$bound = "========_".uniqid("BCFMail"). "==_"; // Delimiter
$headers = "MIME-Version: 1.0n".
"Content-Type: multipart/mixed; boundary="$bound"n".
" Date: ".date("D, d M H:i:s Y ")."n".
"From: $fromn".
"To: $mton".
"Cc: $ mccn".
"Subject: $msubjectn".
"Status: n".
"X-Status:n".
"X-Mailer: MY Email Interfacen". 🎜> " X-Keywords:nn";
$content="--".$bound."n"."Content-Type:text/plain;charset="GB2312"nn".$mbody.$sign."n ";
$end = "n"."--".$bound."--n";
$sock = popen("$sendmailpath -t -f 'webmaster@backhome.com.cn' ",'w');
fputs($sock, $headers);
fputs($sock, $content);
fputs($sock, $end);
fputs($sock , ".n");
fputs($sock, "QUITn");
pclose($sock);
}