使用phpMailer发送邮件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - Mail() basic test</title>
</head>
<body>
<?php
require_once $_SERVER [DOCUMENT_ROOT] . '/lib/PHPMailer/class.phpmailer.php';
$mail = new PHPMailer (); // defaults to using php "mail()"
$mail->Host = "smtp.qq.com"; //设置SMTP服务器
$mail->Hostname = "smtp.qq.com";
$mail->IsSMTP (); // telling the class to use SMTP
$mail->SMTPAuth = true; // SMTP服务器是否需要验证
//$mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent
//$mail->SMTPSecure = "ssl";
$mail->Port = 25; //设置SMTP服务器端口
$mail->Username = "1024114660"; //邮箱账号
$mail->Password = "*******************"; //邮箱密码
$mail->SetFrom ( '1024114660@qq.com', '杜晓孔' );
$mail->AddReplyTo ( "duxiaokong@sina.com", "First Last" );
$mail->AddReplyTo ( "1024114660@qq.com", "First Last" );
$address = "***************@qq.com";
$mail->AddAddress ( $address, "MR.du" );
$mail->Subject = "主题部分";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //可选项,当不支持显示html显示
$body = file_get_contents ( 'http://www.baidu.com' );
//$body = eregi_replace ( "[\]", '', $body );
$mail->MsgHTML ( $body );
$mail->AddAttachment ( "images/001.jpg", '附件名1.jpg' ); // 附件,不能上传相同的附件
$mail->AddAttachment ( "images/002.jpg", '附件名.jpg' ); // 第二个参数为附件显示的名字,如果没有则默认使用文件名
if (! $mail->Send ()) {
   echo "Mailer Error: " . $mail->ErrorInfo;
} else {
   echo "Message sent!";
}
?>
</body>
</html>
官方网站: http://phpmailer.worxware.com/
phpMailer下载地址:
http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值