SoFunction
Updated on 2025-03-09

Super simple email sending program

Recently, I built a news system and wrote this mini program to imitate the online sending function of major websites, hoping it will be useful to all novices.
I did not give part of the code, only the key parts. Among them, shouxin represents the address of the recipient, shouren represents the name of the recipient, jixin represents the address of the sender, and faren represents the name of the sender. id is the parameter passed in the previous one, and it is useless to you at all.

<?
if($shouxin=="")
{
echo "Not sending the address of the recipient";
}else{
$to=explode(',',$shouxin);
$tocount=count($to);
$headers ="From:".$jixin."n";
$subject="Receive";
$body ="Hello.$shouren";
$body.="n";
$body.="Your friend$faren";
$body.="I recommend you to give you an article http://127.0.01.1/myweb/biye/news/?id=$id ";
$body.="n";
$body.="$content";
for($i=0;$i<$tocount;$i++) {
               if(mail($to[$i], $subject, $body,$headers))
          {
echo "Send successfully!";
            }else{
echo "Send failed, please resend.";
             exit();}
        }

}
?>