侧边栏壁纸
博主头像
千古互动

QQ:54505339

  • 累计撰写 40 篇文章
  • 累计收到 1 条评论

记录 魔方财务 插件 SMTP 发信

2024-5-5 / 0 评论 / 1868 阅读
// sendmail('收信人','标题','邮件内容');

sendmail('54505339@qq.com','用户操作消息',' 用户:'.$userid.' <br>主机名: '.$vserverid.' 执行重启');

function sendmail($to,$subject,$body)
{
    $mianban_smtp_id1= '';//smtp服务器
    $mianban_smtp_id2= '';//发信邮箱
    $mianban_smtp_id3= '';//邮箱密码
    $mianban_smtp_id4= 'utf-8';//网页编码
    $mianban_smtp_port ='465';// 发信 协议 25 / 465

if(mianban_smtp_port  =='25'){
  $smtp_host=$mianban_smtp_id1;//smtp服务器 mianban_smtp_id1  
}else{
  $smtp_host='ssl://'.$mianban_smtp_id1;//smtp服务器 mianban_smtp_id1  
}

$user=$mianban_smtp_id2;//发信邮箱 mianban_smtp_id2
$pass=$mianban_smtp_id3;//邮箱密码 mianban_smtp_id3
$charset=$mianban_smtp_id4;//根据自己的网页编码选择 mianban_smtp_id4
$header= "MIME-Version:1.0\r\n";
$header.= "Content-Type:text/html; charset=".$charset."\r\n";
$header.= "To: ".$to."\r\n";
$header.= "From: ".$user."\r\n";
$header.= "Subject: "."=?".strtoupper($charset)."?B?".base64_encode($subject)."?="."\r\n";
$header.= "Date: ".date("r")."\r\n";
$header.= "X-Mailer: By PHP(".phpversion().")\r\n";
list($msec, $sec) = explode(" ", microtime());
$header.= "Message-ID: ".date("YmdHis", $sec).".".$msec."\r\n";
$sent = 0;
$to_arr = explode(";", $to);
foreach ($to_arr as $rcpt_to)
{
$sock = @fsockopen($smtp_host, $mianban_smtp_port, $errno, $errstr, 10);
if ($sock && smtp_ok($sock)) {
if (smtp_cmd($sock,"HELO localhost"))
if (smtp_cmd($sock,"AUTH LOGIN ".base64_encode($user))) 
if (smtp_cmd($sock,base64_encode($pass)))
if (smtp_cmd($sock,"MAIL FROM:<".$user.">")) 
if (smtp_cmd($sock,"RCPT TO:<".$to.">"))
if (smtp_cmd($sock,"DATA")) 
if (smtp_data($sock,$header,$body)) 
if (smtp_cmd($sock,"QUIT")) 
$sent++;
fclose($sock);
}
}
return $sent;
}
function smtp_cmd($sock,$cmd)
{
fputs($sock, $cmd."\r\n");
return smtp_ok($sock);
}
function smtp_data($sock,$header,$body)
{
fputs($sock,$header."\r\n");    
fputs($sock,$body."\r\n.\r\n");
return smtp_ok($sock);
}
function smtp_ok($sock)
{
$response = fgets($sock, 512);
if (!preg_match("/^[23]/", $response))
{
fputs($sock, "QUIT\r\n");
fgets($sock, 512);
return FALSE;
}
return TRUE;
}