一聚教程网:一个值得你收藏的教程网站

热门教程

PHP利用QQ免费邮箱发送邮件实例

时间:2022-06-24 22:03:35 编辑:袖梨 来源:一聚教程网

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";
}
}
?>

调用上边的函数来发送邮件:

 代码如下 复制代码

$result= send_mail("[email protected]","[email protected]","test","test","","");

注:如果没有QQ免费邮箱的朋友,可以自己去腾讯网站注册一个,然后添加成员和DNS,如果没有DNS服务器的话,就添加二个mx记录,比如使用dnspod。

热门栏目