台州温岭做网站请找我们 (专业建站 | 诚信服务) 13958630945 在线客服 联系技术

佳源设计|台州网站建设|佳源网页设计

网站当前位置: 首页>>企业邮箱知识>>php邮件发送函数sendmail
企业邮箱知识
如何利用别名的方式解析域名的M
如何用Foxmail来接收企业
企业邮局如何设置能让管理员监控
企业邮箱注册成功后使用教程
什么是POP3以及什么是SMT
WebMail使用帮助
邮箱域名解析,如何查看是否生效
如果现在购买了邮箱,以后不够用
企业邮局使用指南!
如何设置OUTLOOK来收发邮
Foxmail 邮件导出导入
如何将Foxmail收走的邮件
iPhone中设置使用企业邮箱
安卓手机如何使用邮箱客户端收发
企业邮箱域名解析方法
全球云邮企业邮箱用户手册
php邮件发送函数sendma
 
 建站知识搜索
 
 企业邮箱知识 > php邮件发送函数sendmail

php邮件发送函数sendmail

2213次浏览
2020-11-24

/************JS*******************/

/************JS*******************/

php实例mail.php

/*
使用前先设置发信服务器、邮箱、密码、编码。


php邮件发送函数sendmail(收件地址,标题,内容)说明:
收件地址可以是多个邮箱,用分号(;)隔开。
返回值:成功发送的邮件数。
调试:把本文件内echo前面的注释去掉即可。


修改编写:https://www.52-life.net/
*/
ini_set("display_errors", "Off");
error_reporting(0);

$arr=array();
$email=$_POST["email"];
$uname=$_POST["name"];
$company=$_POST["company"];
$country=$_POST["country"];
$mailcontent="客户姓名: ".$uname."
客户邮箱: ".$email."
公司: ".$company."
国籍: ".$country."
留言信息: ".$_POST["inquiries"];


sendmail(date("Y-m-d")."最新信息",$mailcontent);


function sendmail($subject,$body)
{
$smtp_host="smtp.qq.com"; //smtp服务器
$user="xxxx@qq.com"; //发信邮箱
$pass="123456"; //邮箱密码(QQ授权码,开启方式参考https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256)
$to="xxx@xxx.cn"; //收信地址
$charset="utf-8"; //根据自己的网页编码选择


$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, 25, $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");
$arr['state']=0;
$arr['msg']='
Failure!
Error Message:'.$response;
exit(json_encode($arr));
//fgets($sock, 512);
return FALSE;
}
return TRUE;
}


$arr['state']=0;
$arr['msg']='
THANK YOU!
Your inquiry has been submitted.
We will email you within today.';
exit(json_encode($arr));


页面所在本站地址: http://www.52-life.net/N_php_sendmail.htm
上一篇 >>No News
下一篇 >>企业邮箱域名解析方法