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

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

PHP中文网
PHP中文网원래의
2016-05-25 17:02:151140검색

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으로 문의하세요.