PHP发邮件的例子,发邮件当然需要一个客户端邮箱,今天这个例子是使用QQ免费企业邮箱来做为发邮件的邮箱,
代码如下 |
复制代码 |
include "PHPMailer/class.phpmailer.php";
function send_mail($frommail,$tomail,$subject,$body,$ccmail,$bccmail){
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug;
$mail->Host = "smtp.qq.com";
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->Username = "[email protected]";
$mail->Password = "******";
$mail->AddReplyTo($frommail, 'tankzhang');
$mail->AddAddress($tomail);
$mail->SetFrom($frommail, 'tankzhang');
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->MsgHTML($body);
if(!$mail->Send())
{
echo "邮件发送失败. ";
echo "错误原因: " . $mail->ErrorInfo;
exit;
}else{
echo "success";
}
}
?>
|
调用上边的函数来发送邮件:
注:如果没有QQ免费邮箱的朋友,可以自己去腾讯网站注册一个,然后添加成员和DNS,如果没有DNS服务器的话,就添加二个mx记录,比如使用dnspod。