PHP使用pear內建的mail類庫發郵件的方法_php技巧

來源:互聯網
上載者:User

本文執行個體講述了PHP使用pear內建的mail類庫發郵件的方法。分享給大家供大家參考。具體如下:

這裡用pear內建的mail類庫發郵件,可以用pear install 命令來安裝對應的庫

body = "<a href='http://www.baidu.com/' target='_blank'>點我重建密碼</a>";sendMail_smtp("xxxxxxxx@qq.com",'測試',$body);function sendMail_smtp($smtpemailto,$mailsubject,$mailbody){ //error_reporting(7); require_once 'Mail.php'; require_once 'Mail/mime.php'; $from = 'admin@xxx.com'; $to = $smtpemailto; $password = 'xxxxxx'; $mail_config=array(   "host"=>"smtp.ym.163.com",   "port"=>25,   "auth"=>true,   "username"=>$from,   "password"=>$password,   "from"=>$from, ); $hdrs = array(   'From'=>$from,   'To' => $to, //收信地址   'Subject'=>$mailsubject ); $mime = new Mail_mime(); //$mime->setTXTBody($text); //添加附件 //$mime->addHTMLImage('php.gif','image/gif','12345',true); $mime->_build_params['html_charset'] = "utf-8";//設定編碼格式 $mime->_build_params['head_charset'] = "utf-8";//設定編碼格式  $mime->setHTMLBody($mailbody); $body = $mime->get(); $hdrs = $mime->headers($hdrs); $mail = Mail::factory('smtp',$mail_config); $succ = $mail->send($to,$hdrs,$body); if (PEAR::isError($succ)) {  //echo 'Email sending failed: ' . $succ->getMessage();  $err = 'Email sending failed: ' . $succ->getMessage();  $content = $to."\\t".date('Y-m-d H:i:s')."\\t ".$err." \\r\\n" ; } else {  //$content = $to."\\t".date('Y-m-d H:i:s')."\\t Email sent succesfully \\r\\n" ;  return true; }}

希望本文所述對大家的php程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.