unable to select [11]: Resource temporarily unavailable (max_fd=592)php
首先在163郵箱中開啓smtp受權(imap和pop兩個我都開了)thinkphp
composer require phpmailer/phpmailer
在common.php中寫一個公共方法:apache
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: 流年 <liu21st@gmail.com> // +---------------------------------------------------------------------- // 應用公共文件 // 發送郵件 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 = 'chenyingying1016@163.com'; // SMTP username $mail->Password = '這裏填寫受權碼'; // 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('chenyingying1016@163.com', '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); } }
裏要注意$mail->SMTPOptions 這個屬性。若是是php5 不會影響這個發送結果。 若是是php7 不添加這個屬性。會提示鏈接smtp 失敗!!!!!!!!!php7
mailto($data['email'], '註冊管理員成功!', '註冊管理員成功!');
成功收取到短信composer