首先有一个基于php的邮件发送插件,phpmailer,集成了很多发送电子邮件的功能,我用的就是
这个,直接使用第三方的邮件帐户密码,使用第三方的smtp服务就可以,不用再本地在安装或者
配置负载的邮件发送服务。
require_once'class.phpmailer.php');//引入类
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.qq.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtp.qq.com"; // sets the SMTP server 腾讯的就不错
$mail->Port = 25; // set the SMTP port for the GMAIL server smtp 端口,默认25
$mail->Username = "XXXXXXX@qq.com"; // SMTP 帐号
$mail->Password = "XXXXXXX"; // SMTP 密码
$mail->SetFrom('kukuspeak@bositech.com', "");//邮件来源声明
$mail->AddBCC("simapple@live.com","XXXXX");//这里是密送给另外一个邮箱,至于什么是密送,可以去wiki smtp
$mail->Subject="邮件的标题";
$content=<<
这里可以写任何的html代码,引用的图片和样式要写成自己网站的哦
EOT;
$mail->MsgHTML($content);//指定邮件内容,格式为html,也就可以自定义样式
$mail->AddAddress("simapple@live.com");//指定邮件接收方地址
$mail->Send();//发送
完成以上代码的执行,就可以发送邮件出去了,很简单,对于有邮件发送需求的业务,可能会有帮助