


ThinkPHP How to send emails through PHPMailer to corporate mailboxes
Maybe you need to send emails to website users due to work needs, but with so many customers you cannot send them manually one by one, so I will bring you a good way to use PHP to help you solve this tedious problem. task.
I have been using the 163 mailbox to send files that need to be processed, but if the operation is too frequent [or there are other problems], it will cause the sending to fail. On the contrary, it seems that there has not been a similar situation when using QQ, but The QQ mailbox configuration is slightly different from that of 163. I’ll post it here to prevent my friends from stepping into a trap. I won’t go into more details below. Let’s take a look at the detailed introduction.
Advantages of PHPMailer:
Can run on any platform
Supports SMTP authentication
Specify multiple recipients when sending emails , Cc address, Bcc address and reply address; Note: Adding Cc and Bcc is only supported by SMTP mode under the win platform
Supports multiple email encodings including: 8bit, base64, binary and quoted-printable
Supports redundant SMTP servers, that is, you can specify the main SMTP server address or only the backup SMTP server
Supports emails with attachments, and you can add attachments in any format to emails—of course it’s up to you The server has enough bandwidth to support
custom email header information, which is similar to sending header information in PHP through the header function
supports making the email body into HTMl content , then you can insert pictures into the email body
Flexible debug support
Tested and compatible SMTP servers include: Sendmail, qmail, Postfix, Imail, Exchange, etc.
1. Download PHPMailer
Because there are many versions, I will share the packaged version I use here. Friends who use other versions can use their own
Download address: http://xiazai.jb51.net/201711/yuanma/phpmailer(jb51.net).rar
2. Place PHPMailer
I I created a folder named [Plugin] in the root directory specifically for various plug-ins, and then directly placed PHPMailer under the Plugin folder
3. Let’s code
I will put my code here, you can modify it as needed
function sendMail($to,$title,$content){ require('./Plugin/phpmailer/class.phpmailer.php'); try { $mail = new \PHPMailer(true); $mail->IsSMTP(); $mail->SMTPSecure = 'ssl'; $mail->CharSet = 'UTF-8'; $mail->SMTPAuth = true; //开启认证 $mail->Port = 465; //网易为25 $mail->Host = "smtp.qq.com"; $mail->Username = "******"; //qq此处为邮箱前缀名 163为邮箱名 $mail->Password = "******"; $mail->AddReplyTo("******@qq.com", "******");//回复地址 $mail->From = "******@qq.com"; $mail->FromName = '******'; $mail->AddAddress($to); $mail->Subject = $title; $mail->Body = $content; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示 $mail->WordWrap = 80; // 设置每行字符串的长度 //$mail->AddAttachment("f:/test.png"); //可以添加附件 $mail->IsHTML(true); $mail->Send(); echo '邮件已发送'; } catch (phpmailerException $e) { echo "邮件发送失败:" . $e->errorMessage(); } }
Copy the above code changes directly into your The control machine can
Things to note:
$mail->Port = 465; //网易163 25 $mail->Host = "smtp.qq.com"; $mail->Username = "**"; //qq此处为邮箱前缀名 163为邮箱名 $mail->Password = "******";
In this case, NetEase’s Port is 25
Username, NetEase can directly use the email name. For QQ mailbox, please enter the email prefix [user name] "eg.1214982635@qq.com Please enter 1214982635"
Password NetEase directly Enter your email password [if you have an authorization code, enter the authorization code], please enter the authorization code via QQ, and send a text message to generate
I believe you have mastered it after reading these cases. Method, for more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
php uses git deployment environment
Detailed explanation of javascript data types and git usage code
The above is the detailed content of ThinkPHP How to send emails through PHPMailer to corporate mailboxes. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It has become an indispensable tool in our daily work with the continuous development of the Internet. It is favored by more and more enterprises and individuals, and QQ is a powerful, stable and reliable enterprise email solution. How to register and apply for a QQ account? To help you quickly complete QQ registration, this article will introduce the 15 steps in detail. 1. Open and select the registration page. Enter in the search engine, open your browser "QQ Registration" and select the corresponding link to enter QQ's official website and keywords. 2. Search and click to find the registration entrance. Go to "Register" on the homepage of the QQ official website to enter the registration page, enter and click. 3. Select the registration type according to your needs. Click "Enterprise Registration" or "Personal Registration" on the registration page to enter the corresponding registration flow.

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.

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.

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.

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.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

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.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.
