php发送邮件
phpmailer是大家比较推荐的发送邮件类,下载下来,启用php的sockets扩展。
为了测试邮箱账号是否支持SMTP,特意在Windows Mail里发了一封邮件,测试通过!
于是,照着例子敲,结果却让人郁闷:
SMTP Error: The following recipients failed
心灰意冷呀!在一个帖子里偶然看到一个人提到了swiftmailer,于是试用了一下,终于成功了,眼泪都出来了……
到http://swiftmailer.org/下载最新的swiftmailer,经过摸索,写成了下面的代码,并通过测试。
程序代码
为了测试邮箱账号是否支持SMTP,特意在Windows Mail里发了一封邮件,测试通过!
于是,照着例子敲,结果却让人郁闷:
SMTP Error: The following recipients failed
心灰意冷呀!在一个帖子里偶然看到一个人提到了swiftmailer,于是试用了一下,终于成功了,眼泪都出来了……
到http://swiftmailer.org/下载最新的swiftmailer,经过摸索,写成了下面的代码,并通过测试。
程序代码<?php
//lly365@qq.com
header('content-Type:text/html; charset=utf-8');
require_once 'Swift.php';
require_once 'Swift/Connection/SMTP.php';
require_once "Swift/Authenticator/LOGIN.php";
$conn = new Swift_Connection_SMTP("smtp.sohu.com");
$conn -> setUsername('lorui_com');
$conn -> setPassword('abc123');
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$swift = new Swift($conn);
$message = new Swift_Message("龙睿·LoRui", 'PHP邮件发送,详情请点击<a href="http://www.lorui.com">这里</a>', 'text/html');
echo ($swift->send($message, "lorui.com@gmail.com", "lorui_com@sohu.com")) ? '成功':'失败';
$swift->disconnect();
//lly365@qq.com
header('content-Type:text/html; charset=utf-8');
require_once 'Swift.php';
require_once 'Swift/Connection/SMTP.php';
require_once "Swift/Authenticator/LOGIN.php";
$conn = new Swift_Connection_SMTP("smtp.sohu.com");
$conn -> setUsername('lorui_com');
$conn -> setPassword('abc123');
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$swift = new Swift($conn);
$message = new Swift_Message("龙睿·LoRui", 'PHP邮件发送,详情请点击<a href="http://www.lorui.com">这里</a>', 'text/html');
echo ($swift->send($message, "lorui.com@gmail.com", "lorui_com@sohu.com")) ? '成功':'失败';
$swift->disconnect();

