您好,欢迎访问一九零五行业门户网

php使用pear_smtp发送邮件,pear_smtp发送邮件_PHP教程

php使用pear_smtp发送邮件,pear_smtp发送邮件php自带的mail函数比较蛋疼,在win下配置了sendmail还是无法发送邮件。而使用第三方的pear/mail可以直接通过smtp连接邮件发送服务器。如(smtp.163.com)。从而没有必要在本机上安装sendmail等类似软件。
确保pear mail包已经安装。
$from, 'to' => $to, 'subject' => $subject); $smtp = mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, // 'debug'=>true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (pear::iserror($mail)) { echo( . $mail->getmessage() .
); } else { echo(message successfully sent!
); } ?>
这是非加密方式。
phper 多数使用 mail 函数来发送邮件,但我们可以使用其他的 smtp 服务器来发送,这里推荐使用 pear's mail package 来发送邮件。
$subject = this mail is sent from smtp.;$mail_body = this is the body of the mail which is sent using smtp.;$from = from: from name ; $to = to: to name ; $receiver = toaddress@xpertdeveloper.com; // setting up the headers$headers[from] = $from; $headers[to] = $to; $headers[subject] = $subject; $headers[reply-to] = reply@address.com; $headers[content-type] = text/plain; charset=iso-2022-jp; $headers[return-path] = returnpath@address.com; // setting up the smtp setting$smtp_info[host] = smtp.server.com; $smtp_info[port] = 25; $smtp_info[auth] = true; $smtp_info[username] = smtp_user; $smtp_info[password] = smtp_password; // creating the pear mail object :$mail_obj =& mail::factory(smtp, $smtp_info); // sending the mail now$mail_sent = $mail_obj->send($receiver, $headers, $mail_body); // if any error the see for that here:if (pear::iserror($mail_sent)) { print($mail_sent->getmessage());}
第三个案例:
在使用以下源代码前,请配置好pear的路径,下载net_smtp包
在php.ini文件中根据你的操作系统选择不同的设置方法
; unix: /path1:/path2 include_path = .:./php/pear;; windows: \path1;\path2;include_path = .;c:\php\pearrequire 'net/smtp.php';$host = '126.com';//smtp服务器的ip或域名$username= 'arcow';//登陆smtp服务器的用户名$password= 'secret';//登陆smtp服务器的密码$from = 'arcow@126.com'; //谁发的邮件$rcpt = array('test@test.com', 'arcow@126.com');//可设多个接收者$subj = subject: 你是谁\n;//主题$body = test it;//邮件内容/* 建立一个类 */if (! ($smtp = new net_smtp($host))) { die(无法初始化类net_smtp!\n);}/* 开始连接smtp服务器*/if (pear::iserror($e = $smtp->connect())) { die($e->getmessage() . \n);}/* smtp需要身份验证 */$smtp->auth($username,$password,plain);/*设置发送者邮箱 */if (pear::iserror($smtp->mailfrom($from))) { die(无法设置发送者邮箱为 \n);}/* 设置接收邮件者 */foreach ($rcpt as $to) { if (pear::iserror($res = $smtp->rcptto($to))) { die(邮件无法投递到 : . $res->getmessage() . \n); }}/* 开始发送邮件内容 */if (pear::iserror($smtp->data($subj . \r\n . $body))) { die(unable to send data\n);}/* 断开连接 */$smtp->disconnect();echo 发送成功!;?>
以上就是本文的全部内容,php利用pear_smtp发送邮件的三个案例,希望对大家学习php程序设计有所帮助。
您可能感兴趣的文章:php中通过smtp发邮件的类,测试通过php下使用smtp发邮件的代码phpmailer邮件类利用smtp.163.com发送邮件方法php mail 通过windows的smtp发送邮件失败的解决方案php使用smtp发送支持附件的邮件示例php实现支持ssl连接的smtp邮件发送类php使用pear自带的mail类库发邮件的方法php使用pear发送邮件(windows环境)php使用pear实现mail发送功能 windows环境下配置pear
http://www.bkjia.com/phpjc/1121288.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1121288.htmltecharticlephp使用pear_smtp发送邮件,pear_smtp发送邮件 php自带的mail函数比较蛋疼,在win下配置了sendmail还是无法发送邮件。而使用第三方的pear/mail可以直...
其它类似信息

推荐信息