文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>用PHP发邮件

用PHP发邮件

时间:2009-07-23  来源:hkebao

一、使用PHP内置的mail函数发邮件有诸多限制: For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time. If you use another mail program, such as qmail or postfix, be sure to use the appropriate sendmail wrappers that come with them. PHP will first look for sendmail in your PATH, and then in the following: /usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib. It's highly recommended to have sendmail available from your PATH. Also, the user that compiled PHP must have permission to access the sendmail binary. 而且邮件服务器对发邮件有验证要求的时候,也无法寄出。   在参考了网上诸多实例,并根据RFC821规范,原理如下:     与服务器建立Socket连接->向服务器端口发送相关命令-> 与服务器交互->Action OK   根据以上原理,首先要建立Socket连接,可参考PHP手册,这里使用Pear类库:Net_Smtp、Net_Socket、Mail这三个类库,首 先Pear install (--alldeps)安装三个Pear类库,记得要在PHP.ini里检查一下include_path有没有把pear的路径包含进来。 <?php        require_once 'Mail.php';   $conf['mail'] = array(
    'host'     => '**.**.**.**',         //smtp服务器地址,可以用ip地址或者域名
    'auth'     =>true,                  //true表示smtp服务器需要验证,false代码不需要
    'username' => '***',             //用户名
    'password' => '******'          //密码
  );
  $headers['From']    = '***@*****.tw';              //发信地址
  $headers['To']      = '**qg@****.tw';              //收信地址
  $headers['Subject'] = 'test mail send by php';          //邮件标题
  $mail_object = &Mail::factory('smtp', $conf['mail']);  
  $body = 'hello world!!!';                         //邮件正文
  $mail_res = $mail_object->send($headers['To'], $headers, $body);        //发送
  if($mail_res) {                         //检测错误
   print_r($mail_res);
   echo "send mail is OK";
  }else{
   echo "send mail is something wrong!";
  }
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载