While not many sites still use the site’s message and form collection features, a small percentage of users still do. Have you ever thought that when the website receives a new message, or when a user submits a new form information, you want the program to automatically send them to our QQ mailbox? To tell the truth, a lot of people do not often log in the website background, but QQ, wechat is always online, when there is a new mail arrived, you can timely receive mail information. If the website message and form information can be timely sent to the mailbox, it is not afraid of missing what customer information.
We found a code for PHPMail on GitHub. However, this code is composed of multiple files, the use of the need to master some BASIC PHP, in order to combine with our website.
Since some users didn’t understand the code, I reorganized PHPMail into a single file and simplified some of the configuration information to make it easier to use and deploy. To make it easier to use when you need it, just follow these simple steps and apply it to your website.
Enable SMTP and set the authorization code in the QQ email account setting
Login our QQ mailbox, and click the account Settings – > account below, down, down to POP3 / IMAP/SMTP/Exchange/CardDAV CalDAV service services TAB, select open POP3 / SMTP service, and click the generate the authorization code below links, Generates an authorization code for the configuration in the mailbox. The authorization code consists of 16 characters. After the generation, it is saved for later use. When you generate an authorization code, you may be asked to verify the encryption of your email address as normal.
Download mail.zip and configure email accounts
Download mail.zip from the attachment and unzip it to get mail.php.
Open mail.php with a text editor and go to the account configuration section:
// Email configuration information
$config = array(
'server'= >'smtp.qq.com'.'use_ssl'= >'1'.'port'= >'465'.'account'= >'Your email account @qq.com'.'name'= >'Enterprise Website Security Assistant'.'password'= >'Your Authorization password',);Copy the code
Fill in your account information here, replace your email account @qq.com with your real email address, and replace your authorization password with the authorization code generated above. Save last.
You only need to replace these two parts to complete the account configuration.
At this point, you need to upload it to the root of the site and wait for the next call to process it.
Docking website, revamp form
The mail.php file supports both post and GET forms, and supports JSON, HTML, and blank returns.
Method one: Keep the original form
This method requires you to know some PHP code, otherwise it can be quite cumbersome to handle
Take the message form of our website as an example. In order not to affect the background record of the message on the original website, we need to add a return field to the HTML part of the form to declare that the HTML or JSON will be returned.
<input type="hidden" name="return" value="empty" />
Copy the code
Find the receiving function in the received PHP code and add the call:
// Introduce the send mail processing file here
require_once('mail.php');
Copy the code
Method two sends the request directly to mail.php
This is the easiest way to do this, you don’t need to know PHP, just change the address of the message form to mail.php.
Also, it’s best to add a new return field to the form. Not adding it does not affect usage, because the default is to return HTML.
<input type="hidden" name="return" value="html" />
Copy the code
Then change the action value to /mail.php
Approach three: Submit the form using Ajax
If your form was originally submitted using Ajax, mail.php can also take over the processing.
So what you need to do is in your submission address, change it to /mail.php? Return = json.
Please download mail.zip from GitHub because you cannot upload zip file