Home Backend Development PHP Tutorial thinkphp implements the method of sending and receiving emails in 163 and QQ mailboxes

thinkphp implements the method of sending and receiving emails in 163 and QQ mailboxes

Jun 06, 2018 pm 02:00 PM
thinkphp mail

This article mainly introduces the method of thinkphp to realize sending and receiving emails in 163 and other mailboxes. It has been tested on 163 NetEase mailbox, and I would like to share it with you.

It took a long time to explore step by step, and finally first 163 The test on NetEase mailbox was successful. 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>
Copy after login

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格式邮件
Copy after login

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());
}
Copy after login

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;);
 }
}
Copy after login

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格式邮件
Copy after login

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

The above is how thinkphp implements sending and receiving emails to 163 and other mailboxes. I hope it will be helpful to everyone's learning.

Related recommendations:

ThinkPHP basic add, delete, check and modify operation example tutorial

The above is the detailed content of thinkphp implements the method of sending and receiving emails in 163 and QQ mailboxes. For more information, please follow other related articles on the PHP Chinese website!

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Outlook emails lost from control panel in Windows 11 Outlook emails lost from control panel in Windows 11 Feb 29, 2024 pm 03:16 PM

Is the Outlook mail icon missing from Windows 11's Control Panel? This unexpected situation has caused confusion and concern among some individuals who rely on OutlookMail for their communication needs. Why don't my Outlook emails show up in Control Panel? There may be several possible reasons why there are no Outlook mail icons in Control Panel: Outlook is not installed correctly. Installing Office applications from the Microsoft Store does not add the Mail applet to Control Panel. The location of the mlcfg32.cpl file in Control Panel is missing. The path to the mlcfg32.cpl file in the registry is incorrect. The operating system is not currently configured to run this application

Word mail merge prints blank page Word mail merge prints blank page Feb 19, 2024 pm 04:51 PM

If you find that blank pages appear when printing a mail merge document using Word, this article will help you. Mail merge is a convenient feature that allows you to easily create personalized documents and send them to multiple recipients. In Microsoft Word, the mail merge feature is highly regarded because it helps users save time manually copying the same content for each recipient. In order to print the mail merge document, you can go to the Mailings tab. But some Word users have reported that when trying to print a mail merge document, the printer prints a blank page or doesn't print at all. This may be due to incorrect formatting or printer settings. Try checking the document and printer settings and make sure to preview the document before printing to ensure the content is correct. if

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

How to use real-time voicemail transcription on iPhone How to use real-time voicemail transcription on iPhone Nov 18, 2023 pm 04:03 PM

What is real-time voicemail transcription? Live Voicemail Transcription is an innovative feature introduced in iOS 16 that allows iPhone users to view a live transcription of their voicemail while leaving it. This feature utilizes advanced speech recognition technology to convert spoken words into text, providing a convenient and accessible way to stay up to date on the latest news without having to listen to them entirely. Benefits of Using Live Voicemail Transcription Live Voicemail Transcription offers several advantages to iPhone users: Improved Productivity: By providing real-time transcription, Live Voicemail Transcription saves users time and effort by eliminating the need to listen to the entire voicemail. . This allows users to quickly scan the content of voicemails and prioritize their responses. Accessibility for hearing-impaired users

See all articles