


thinkphp implements the method of sending and receiving emails in 163 and QQ mailboxes
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:
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:
'MAIL_HOST' =>'smtp.163.com',//smtp服务器的名称 'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证 'MAIL_USERNAME' =>'zha****22@163.com',//发件人的邮箱名 'MAIL_PASSWORD' =>'olagbqsyeyhilcwu',//163邮箱发件人授权密码 'MAIL_FROM' =>'zha****22@163.com',//发件人邮箱地址 'MAIL_FROMNAME'=>'天空还下着雪',//发件人姓名 'MAIL_CHARSET' =>'utf-8',//设置邮件编码 'MAIL_ISHTML' =>TRUE, // 是否HTML格式邮件function.php public function:
/* * 发送邮件 * @param $to string * @param $title string * @param $content string * @return bool * */ function sendMail($to, $title, $content) { Vendor('PHPMailer.PHPMailerAutoload'); $mail = new PHPMailer(); //实例化 $mail->IsSMTP(); // 启用SMTP $mail->Host=C('MAIL_HOST'); //smtp服务器的名称(这里以QQ邮箱为例) $mail->SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证 $mail->Username = C('MAIL_USERNAME'); //发件人邮箱名 $mail->Password = C('MAIL_PASSWORD') ; //163邮箱发件人授权密码 $mail->From = C('MAIL_FROM'); //发件人地址(也就是你的邮箱地址) $mail->FromName = C('MAIL_FROMNAME'); //发件人姓名 $mail->AddAddress($to,"尊敬的客户"); $mail->WordWrap = 50; //设置每行字符长度 $mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件 $mail->CharSet=C('MAIL_CHARSET'); //设置邮件编码 $mail->Subject =$title; //邮件主题 $mail->Body = $content; //邮件内容 $mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示 return($mail->Send()); }add method call:
public function add() { if(SendMail($_POST['mail'],$_POST['title'],$_POST['content'])) { $this->success('发送成功!'); } else { $this->error('发送失败'); } }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 port1. Set an independent email password
2. Enable POP3/SMTP service
'MAIL_HOST' =>'smtp.qq.com',//smtp服务器的名称 'MAIL_SMTPAUTH' =>TRUE, //启用smtp认证 'MAIL_USERNAME' =>'541****34@qq.com',//发件人邮箱名 'MAIL_PASSWORD' =>'s****1241',//qq邮箱发件人独立密码 'MAIL_FROM' =>'541****34@qq.com',//发件人地址 'MAIL_FROMNAME'=>'恋狱',//发件人姓名(qq邮箱昵称) 'MAIL_CHARSET' =>'utf-8',//设置邮件编码 'MAIL_ISHTML' =>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 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!

In PHP, you can use session_status() or session_id() to check whether the session has started. 1) Use the session_status() function. If PHP_SESSION_ACTIVE is returned, the session has been started. 2) Use the session_id() function, if a non-empty string is returned, the session has been started. Both methods can effectively check the session state, and choosing which method to use depends on the PHP version and personal preferences.

Sessionsarevitalinwebapplications,especiallyfore-commerceplatforms.Theymaintainuserdataacrossrequests,crucialforshoppingcarts,authentication,andpersonalization.InFlask,sessionscanbeimplementedusingsimplecodetomanageuserloginsanddatapersistence.

Managing concurrent session access in PHP can be done by the following methods: 1. Use the database to store session data, 2. Use Redis or Memcached, 3. Implement a session locking strategy. These methods help ensure data consistency and improve concurrency performance.

PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
