php用法pear_smtp发送邮件_.docx

上传人:啊飒飒 文档编号:11622180 上传时间:2021-08-26 格式:DOCX 页数:6 大小:13.31KB
返回 下载 相关 举报
php用法pear_smtp发送邮件_.docx_第1页
第1页 / 共6页
php用法pear_smtp发送邮件_.docx_第2页
第2页 / 共6页
php用法pear_smtp发送邮件_.docx_第3页
第3页 / 共6页
php用法pear_smtp发送邮件_.docx_第4页
第4页 / 共6页
php用法pear_smtp发送邮件_.docx_第5页
第5页 / 共6页
亲,该文档总共6页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《php用法pear_smtp发送邮件_.docx》由会员分享,可在线阅读,更多相关《php用法pear_smtp发送邮件_.docx(6页珍藏版)》请在三一文库上搜索。

1、php用法pear_smtp发送邮件_ PHP自带的mail函数比较蛋疼,在win下配置了sendmail还是无法发送邮件。而用法第三方的pear/mail可以挺直通过smtp连接邮件发送服务器。如()。从而没有必要在本机上安装sendmail等类似软件。 确保PEAR Mail包已经安装。 ?php require_once vendor/autoload.php; $from = ; $to = test ; $subject = Hi!; $body = Hi,nnHow are you?; $host = ; $port = 25; $username = ; $password =

2、test123; $headers = array (From = $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(p . $mail-getMessage()

3、. /p); else echo(pMessage successfully sent!/p); ? 这是非加密方式。 PHPer 多数用法 mail 函数来发送邮件,但我们可以用法其他的 SMTP 服务器来发送,这里推举用法 PEARs 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 ; $rec

4、eiver = ; / Setting up the headers $headersFrom = $from; $headersTo = $to; $headersSubject = $subject; $headersReply-To = ; $headersContent-Type = text/plain; charset=ISO-2022-JP; $headersReturn-path = ; / Setting up the SMTP setting $smtp_infohost = ; $smtp_infoport = 25; $smtp_infoauth = true; $sm

5、tp_infousername = smtp_user; $smtp_infopassword = 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

6、($mail_sent-getMessage(); 第三个案例: 在用法以下源代码前,请配置好pear的路径,下载net_smtp包 在php.ini文件中依据你的操作系统选择不同的设置方法 ; UNIX: /path1:/path2 include_path = .:./php/pear ; ; Windows: path1;path2 ;include_path = .;c:phppear require Net/SMTP.php; $host = ;/smtp服务器的ip或域名 $username= arcow;/登陆smtp服务器的用户名 $password= secret;/登陆sm

7、tp服务器的密码 $from = ; /谁发的邮件 $rcpt = array(, );/可设多个接收者 $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,

8、PLAIN); /*设置发送者邮箱 */ if (PEAR:isError($smtp-mailFrom($from) die(无法设置发送者邮箱为 $fromn); /* 设置接收邮件者 */ foreach ($rcpt as $to) if (PEAR:isError($res = $smtp-rcptTo($to) die(邮件无法投递到 $to: . $res-getMessage() . n); /* 开头发送邮件内容 */ if (PEAR:isError($smtp-data($subj . rn . $body) die(Unable to send datan); /* 断开连接 */ $smtp-disconnect(); echo 发送胜利!; ? 以上就是本文的全部内容,php利用pear_smtp发送邮件的三个案例,盼望对大家学习php程序设计有所关心。 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1