Thinkphp3.2.3 frame mail sending function picture and text example details

Time:2020-1-22

The example of this paper describes the function of sending mail in thinkphp3.2.3 framework. To share with you for your reference, as follows:

background

  • In the process of web development, the sending function of e-mail is often used, such as the reminder of receiving consumption bills, the push of Amazon book recommendation, or the e-mail prompt of abnormal operation alarm of the website.

  • The following is a realization process of mail sending function used by phpmailer under the framework of ThinkPHP 3.2.3. It is only for reference. Thank you

1、 Preliminary preparation

1) . first, a little knowledge of STMP

Introduction to STMP Baidu Encyclopedia

2) . open mailbox STMP service

  • Take 163.com email as an example, click “Settings” in the upper navigation bar, and select “POP3 / SMTP / imap” to make the following settings
  • Note down the server address (SMTP server: SMTP. 163. Com)

  • Then click “client authorization password” to set the permission. Generally, SMS will be used to verify and record the authorized login password set by yourself, which needs to be used in the following code.

2、 Code implementation

1) . in the public profile, configure the data

//Mail sending configuration
  'EMAIL_CONFIG' => array(
    'host' => 'smtp.163.com',
    'post' => '25',
    'username' = > 'XXXXXXXX @ 163. Com', // todo email account
    'password' = > 'XXXXXXX', // todo client authorization password
    'sender' = > 'woodman', // todo sender nickname
  ),

2) The core code of. Email is as follows

  • Note the location of the phpmailer code package so that the following email class can be instantiated
  • This code is mainly to call configuration file data, no change, need in-depth learning can read

3) . design front-end display interface

  • Route:./Application/M/Vieww/Email/index.html
  • The core JS code is as follows:

function send() {
    var toUrl = "{:U('Email/send')}";
    var postData = $("#form-email").serialize();
    $.ajax({
      type: "POST",
      url: toUrl,
      data: postData,
      dataType: "json",
      success: function (res) {
        layer.msg(res.message);
      }
    });
  }

4) . background code

  • Path: ‘. \ application \ m \ controller \ emailcontroller. Class. PHP’
  • The core code of calling the mail sending function is three lines in the red box in the following figure.

3、 Function realization effect

1) . front end information input

  • Note: if the email is entered incorrectly or the content is filled too casually, it will cause sending failure. The email can be seen in the sender’s email box, and the prompt “sorry, your email has been returned…”.

Message sending front display

2) . receive mailbox successfully

  • If the operation is normal, the corresponding email will be received in the mailbox entered above, but some of them may be in their own “trash can”, please check

Mail received successfully

Three, appendix

1) . reference video:http://coding.imooc.com/learn/list/85.html

2) . source code download:https://github.com/JingYin007/zmPro

For more information about ThinkPHP, readers who are interested in it can see the following topics: introduction to ThinkPHP, summary of operation skills of ThinkPHP template, summary of common methods of ThinkPHP, introduction to CodeIgniter, advanced tutorial of CI (CodeIgniter) framework, introduction to Zend framework and technical summary of PHP template.

I hope that this article will be helpful for you to design your PHP program based on the think PHP framework.

Recommended Today

PHP realizes UnionPay business H5 payment

UnionPay business H5 payment interface document: document address 1: H5 payment interface address: 1: Alipay payment Test address: http://58.247.0.18:29015/v1/netpay/trade/h5-pay Official address: https://api-mop.chinaums.com/ 2: UnionPay payment Test address: http://58.247.0.18:29015/v1/netpay/uac/order Official address: https://api-mop.chinaums.com/ 2: Basic parameters required by the interface The interface uses get parameters. After the interface parameters are directly put into the interface address, the […]