首页 >php教程 >PHP源码 >用pear自带的mail类库发邮件 - PHP

用pear自带的mail类库发邮件 - PHP

PHP中文网
PHP中文网原创
2016-05-25 17:02:151150浏览

php代码

body = "<a href=&#39;http://www.baidu.com/&#39; target=&#39;_blank&#39;>点我重新生成密码</a>";
 
sendMail_smtp("xxxxxxxx@qq.com",&#39;测试&#39;,$body);
 
function sendMail_smtp($smtpemailto,$mailsubject,$mailbody){
    //error_reporting(7);
      
    require_once &#39;Mail.php&#39;;
    require_once &#39;Mail/mime.php&#39;;
 
    $from = &#39;admin@xxx.com&#39;;
    $to   = $smtpemailto;
    $password = &#39;xxxxxx&#39;;
      
    $mail_config=array(
            "host"=>"smtp.ym.163.com",
            "port"=>25,
            "auth"=>true,
            "username"=>$from,
            "password"=>$password,
            "from"=>$from,
    );
      
    $hdrs = array(
            &#39;From&#39;=>$from,
            &#39;To&#39; => $to, //收信地址
            &#39;Subject&#39;=>$mailsubject
    );
      
    $mime = new Mail_mime();
    //$mime->setTXTBody($text);
    //添加附件
    //$mime->addHTMLImage(&#39;php.gif&#39;,&#39;image/gif&#39;,&#39;12345&#39;,true);
    $mime->_build_params[&#39;html_charset&#39;] = "utf-8";//设置编码格式
    $mime->_build_params[&#39;head_charset&#39;] = "utf-8";//设置编码格式 
    $mime->setHTMLBody($mailbody);
    $body = $mime->get();
    $hdrs = $mime->headers($hdrs);
      
    $mail = Mail::factory(&#39;smtp&#39;,$mail_config);
    $succ = $mail->send($to,$hdrs,$body);
      
    if (PEAR::isError($succ))
    {
        //echo &#39;Email sending failed: &#39; . $succ->getMessage();
        $err = &#39;Email sending failed: &#39; . $succ->getMessage();
        $content = $to."\\t".date(&#39;Y-m-d H:i:s&#39;)."\\t ".$err." \\r\\n" ;
    }
    else
    {
        //$content = $to."\\t".date(&#39;Y-m-d H:i:s&#39;)."\\t Email sent succesfully \\r\\n" ;
        return true;
          
    }
      
}
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn