PHP实现本地邮件发送

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_username=***@163.com

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);
    }
}
?>

转载于:https://my.oschina.net/u/1858712/blog/309794

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值