Rumah > Artikel > pembangunan bahagian belakang > PHP使用QQ免费邮箱发送邮件的一个例子_PHP教程
PHP发邮件的例子,发邮件当然需要一个客户端邮箱,今天这个例子是使用QQ免费企业邮箱来做为发邮件的邮箱,
01
02include "PHPMailer/class.phpmailer.php";
03function send_mail($frommail,$tomail,$subject,$body,$ccmail,$bccmail){
04$mail = new PHPMailer();
05$mail->IsSMTP();
06$mail->SMTPDebug;
07$mail->Host = "smtp.qq.com";
08$mail->SMTPAuth = true;
09$mail->Port = 25;
10$mail->Username = "admin@51yip.com";
11$mail->Password = "******";
12$mail->AddReplyTo($frommail, 'tankzhang');
13$mail->AddAddress($tomail);
14$mail->SetFrom($frommail, 'tankzhang');
15$mail->IsHTML(true);
16$mail->Subject = $subject;
17$mail->MsgHTML($body);
18if(!$mail->Send())
19{
20echo "邮件发送失败.
";
21echo "错误原因: " . $mail->ErrorInfo;
22exit;
23}else{
24echo "success";
25}
26}
27?>
调用上边的函数来发送邮件:
1$result= send_mail("admin@163.com","12345@qq.com","test","test","","");
注:如果没有QQ免费邮箱的朋友,可以自己去腾讯网站注册一个,然后添加成员和DNS,如果没有DNS服务器的话,就添加二个mx记录,比如使用dnspod。