本例子是利用phpmailer来登录QQ邮件然后利用QQ邮件向指定邮件发送一封邮件的例子,希望本例子能帮助到各位同学.
PHP发邮件的例子,发邮件当然需要一个客户端邮箱,今天这个例子是使用QQ免费企业邮箱来做为发邮件的邮箱,代码如下:
<?php 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 = "admin@51yip.com"; $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 "邮件发送失败. <p>"; echo "错误原因: " . $mail->ErrorInfo; exit; } else { echo "success"; } }
调用上边的函数来发送邮件, 代码如下:
$result = send_mail("admin@163.com", "12345@qq.com", "test", "test", "", "");
注:
如果没有QQ免费邮箱的朋友, 可以自己去腾讯网站注册一个, 然后添加成员和DNS, 如果没有DNS服务器的话, 就添加二个mx记录, 比如使用dnspod .
文章地址:
转载随意^^请带上本文地址!