search
HomePHP FrameworkThinkPHPHow does the TP framework implement the sending and receiving of 163 or QQ emails?

The following thinkphp framework tutorial column will introduce to you how thinkphp implements 163 and QQ mailboxes to send and receive emails. I hope it will be helpful to friends in need!

It took a long time to explore step by step, and finally the test was successful on 163 NetEase mailbox. I will share the process with everyone below.

Before entering the topic, let’s take a look at the server address and port number of NetEase (163) mailbox:

1. Preparation

To use NetEase mailbox, of course you need to register an account. I don’t need to say more about this, just register it yourself. . .

After registration, you need to enable the POP3/SMTP/IMAP service. When opening the service, a client authorization password is required (mobile phone verification is required here, and MD asks for a mobile phone number in a roundabout way).

Step one:

##Step two:


#After confirmation, the following dialog box will pop up, and the authorization password will also be sent to your text message. Remember this authorization password. Be sure to remember it.


After the service is turned on, if [Name] is not set, you will be prompted to set [Name] before sending the email when writing an email. Of course, you can also set it in advance. good. .


2. Code part

PHPMailer download (after downloading, place PHPMailer in the Vendor directory and another file There are a lot of unnecessary things, just take care of them yourself)

Careful students can check the default port number in the three files class.phpmailer.php class.pop3.php class.smtp.php. The default SMTP port number is 25, which is the same as the non-SSL protocol port number of the SMTP sending server under 163.

html layout:

<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <form action="__URL__/add" method="post" enctype="multipart/form-data">
 收件人邮箱:<input type="text" name="mail"/>
 标题:<input type="text" name="title"/>
 内容<input type="text" name="content"/>
 <input class="button" type="submit" value="发送"/>
 </form>
</body>
</html>

config.php configuration:

&#39;MAIL_HOST&#39; =>&#39;smtp.163.com&#39;,//smtp服务器的名称
&#39;MAIL_SMTPAUTH&#39; =>TRUE, //启用smtp认证
&#39;MAIL_USERNAME&#39; =>&#39;zha****22@163.com&#39;,//发件人的邮箱名
&#39;MAIL_PASSWORD&#39; =>&#39;olagbqsyeyhilcwu&#39;,//163邮箱发件人授权密码
&#39;MAIL_FROM&#39; =>&#39;zha****22@163.com&#39;,//发件人邮箱地址
&#39;MAIL_FROMNAME&#39;=>&#39;天空还下着雪&#39;,//发件人姓名
&#39;MAIL_CHARSET&#39; =>&#39;utf-8&#39;,//设置邮件编码
&#39;MAIL_ISHTML&#39; =>TRUE, // 是否HTML格式邮件

function.php public function:

/*
 * 发送邮件
 * @param $to string
 * @param $title string
 * @param $content string
 * @return bool
 * */
function sendMail($to, $title, $content) {
 Vendor(&#39;PHPMailer.PHPMailerAutoload&#39;);
 $mail = new PHPMailer(); //实例化
 $mail->IsSMTP(); // 启用SMTP
 $mail->Host=C(&#39;MAIL_HOST&#39;); //smtp服务器的名称(这里以QQ邮箱为例)
 $mail->SMTPAuth = C(&#39;MAIL_SMTPAUTH&#39;); //启用smtp认证
 $mail->Username = C(&#39;MAIL_USERNAME&#39;); //发件人邮箱名
 $mail->Password = C(&#39;MAIL_PASSWORD&#39;) ; //163邮箱发件人授权密码
 $mail->From = C(&#39;MAIL_FROM&#39;); //发件人地址(也就是你的邮箱地址)
 $mail->FromName = C(&#39;MAIL_FROMNAME&#39;); //发件人姓名
 $mail->AddAddress($to,"尊敬的客户");
 $mail->WordWrap = 50; //设置每行字符长度
 $mail->IsHTML(C(&#39;MAIL_ISHTML&#39;)); // 是否HTML格式邮件
 $mail->CharSet=C(&#39;MAIL_CHARSET&#39;); //设置邮件编码
 $mail->Subject =$title; //邮件主题
 $mail->Body = $content; //邮件内容
 $mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
 return($mail->Send());
}

add method call:

public function add() {
 if(SendMail($_POST[&#39;mail&#39;],$_POST[&#39;title&#39;],$_POST[&#39;content&#39;])) {
 $this->success(&#39;发送成功!&#39;);
 } else {
 $this->error(&#39;发送失败&#39;);
 }
}

After completing the above work, next visit the address and send an email to 163 (NetEase) mailbox through the form (for example: send to 123456@163.com), or you can send it to yourself. After sending, you will see that the sending was successful. . Next you can log in to your mailbox to check your emails.

QQ mailbox sending and receiving mail

QQ mailbox sending and receiving mail server address and port


Preparation:

1. Set an independent email password
2. Enable POP3/SMTP service

Configuration:

&#39;MAIL_HOST&#39; =>&#39;smtp.qq.com&#39;,//smtp服务器的名称
&#39;MAIL_SMTPAUTH&#39; =>TRUE, //启用smtp认证
&#39;MAIL_USERNAME&#39; =>&#39;541****34@qq.com&#39;,//发件人邮箱名
&#39;MAIL_PASSWORD&#39; =>&#39;s****1241&#39;,//qq邮箱发件人独立密码
&#39;MAIL_FROM&#39; =>&#39;541****34@qq.com&#39;,//发件人地址
&#39;MAIL_FROMNAME&#39;=>&#39;恋狱&#39;,//发件人姓名(qq邮箱昵称)
&#39;MAIL_CHARSET&#39; =>&#39;utf-8&#39;,//设置邮件编码
&#39;MAIL_ISHTML&#39; =>TRUE, // 是否HTML格式邮件

No other changes are required. After completion, not only You can send emails to QQ mailbox users or 163 mailbox users.

The above is the detailed content of How does the TP framework implement the sending and receiving of 163 or QQ emails?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:jb51. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.