Think php5.1 reports an error using phpmailer under php7.3

Time:2021-7-28

Thinkphp5.1 using phpmailer under php7.3 reports an error:

unable to select [11]: Resource temporarily unavailable (max_fd=592)

 

1. Open the mailbox for authorization and obtain the authorization code

First, open SMTP authorization in mailbox 163 (I have both IMAP and pop)

 

 

2. Install phpmailer

composer require phpmailer/phpmailer

Write a public method in common.php:

// +----------------------------------------------------------------------

//Apply public files

//Send mail
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

function mailto($to, $title, $content)
{
    $mail = new PHPMailer(true);
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

    try {
        //Server settings
        $mail->SMTPDebug = 0;                      // Enable verbose debug output
        $mail->CharSet = 'utf-8';
        $mail->isSMTP();                                            // Send using SMTP
        $mail->Host       = 'smtp.163.com';                    // Set the SMTP server to send through
        $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
        $mail->Username   = '[email protected]';                     // SMTP username
        $mail - > password = 'fill in the authorization code here'// SMTP password
        $mail->SMTPSecure = 'ssl';         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
        $mail->Port       = 465;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

        //Recipients
        $mail->setFrom('[email protected]', 'cyy');
        $mail->addAddress($to);     // Add a recipient

        // Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $title;
        $mail->Body    = $content;

        return $mail->send();
    } catch (Exception $e) {
          exception($mail->ErrorInfo, 1001);
    }
}

Note the $mail – > smtpoptions attribute in the. If it is PHP5, it will not affect the sending result. If it is php7, do not add this attribute. You will be prompted that the connection to SMTP failed!!!!!!!!!

 

 

3. Send SMS

Mailto ($data ['email '],' registered administrator succeeded! ',' Registration of administrator succeeded (!);

SMS received successfully