当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP使用pear自带的mail类库发邮件的方法

PHP使用pear自带的mail类库发邮件的方法

2018年05月15日  | 移动技术网IT编程  | 我要评论

奥维拖拉机,陈渠珍,北京夜校

本文实例讲述了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程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网