Home > php教程 > php手册 > PHP利用QQ免费邮箱发送邮件实例

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

WBOY
Release: 2016-05-26 08:21:05
Original
1447 people have browsed it

本例子是利用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, &#39;tankzhang&#39;);
    $mail->AddAddress($tomail);
    $mail->SetFrom($frommail, &#39;tankzhang&#39;);
    $mail->IsHTML(true);
    $mail->Subject = $subject;
    $mail->MsgHTML($body);
    if (!$mail->Send()) {
        echo "邮件发送失败. <p>";
        echo "错误原因: " . $mail->ErrorInfo;
        exit;
    } else {
        echo "success";
    }
}
Copy after login

调用上边的函数来发送邮件, 代码如下:

$result = send_mail("admin@163.com", "12345@qq.com", "test", "test", "", "");

注:

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


文章地址:

转载随意^^请带上本文地址!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template