使用pear:Net_SMTP类发送邮件的例子
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-07-25 09:11:07
original
1643 Les gens l'ont consulté
-
-
require 'Net/SMTP.php';
$host = '126.com';//smtp服务器的ip或域名
- $username= 'arcow';//登陆smtp服务器的用户名
- $password= 'secret';//登陆smtp服务器的密码
- $from = 'jbxue@126.com'; //谁发的邮件
- $rcpt = array('test@test.com', 'jbxue@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 "发送成功!";
- ?>
-
复制代码
|
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
Derniers numéros
-
2025-03-26 19:48:00
-
2025-03-26 19:40:08
-
2025-03-26 12:24:37
-
2025-03-26 12:20:46
-
2025-03-21 13:39:34