php.ini配置
[ mail function ]
SMTP = localhost
smtp_port=25
sendmail_path ="D:\PHP\extras\sendmail\sendmail.exe -t" (sendmail.exe位置)
sendmail.ini配置
[sendmail]
smtp_server=stem.163.com
smyp_port=25
auth_password=***
force_sender=***@163.com(同auth_username)
相关.ini文件配置完成后便能够使用PHP中的mail()函数去发送邮件
sendmail下载地址为:http://glob.com.au
下面是本人所写的发送邮件类
<?php
/**
fenghao
2014-9-3 16:47
SBI
*$mail=new sendMail();
*$mail->setReceiver("XXXXX"); 设置收件人,多个收件人,调用多次,多个收件人请用","隔开
*$mail->setMailInfo("test","<b>test</b>"); 设置邮件主题、内容
*$mail->sendmail(); 发送
*/
class sendMail
{
private $ToUserName; //收件人
private $Subject; //主题
private $Content; //邮件正文
private $Headers; //额外的报头
private $Result; //结果信息
public function setReceiver($to){
$this->ToUserName=$to;
}
public function setMailInfo($subject,$content){
$this->Subject=$subject;
$this->Content=$content;
$headers="MIME-Version: 1.0" . "\r\n";
$headers.="Content-type:text/html;charset=utf8" . "\r\n";
$headers.="From: <>" . "\r\n";
$this->Headers=$headers;
}
public function sendmail(){
if(empty($this->ToUserName)||empty($this->Subject)||empty($this->Content)){
$this->Result=array("errcode"=>"40001","errmsg"=>"no enough information");
}else{
$toUserName=explode(",",$this->ToUserName);
foreach($toUserName as $to){
if(!empty($to)){
$flag=mail($to,$this->Subject,$this->Content,$this->Headers);
if($flag){
$this->Result=array("errcode"=>"0","errmsg"=>"OK");
}else{
$this->Result=array("errcode"=>"40002","errmsg"=>"send fail");
}
}
}
}
return json_encode($this->Result);
}
}
?>