php ssl发送邮件代码

正文开始

邮件扩展 ~~~ "require": { "phpmailer/phpmailer": "^6.2" } ~~~ composer update 安装 ~~~ //发送邮件 public static function mailto($address, $subject='title', $body) { if(!extension_loaded('openssl')) echo "Not Available openssl \n"; $mail = new PHPMailer(true); $mail->IsSMTP(); $posterFromEmail = self::$posterFromEmail; $posterFromPwd = self::$posterFromPwd; if(strpos($posterFromEmail, '163.com') !== false) { $mail->Host = "smtp.163.com"; // SMTP 服务器 } elseif (strpos($posterFromEmail, 'qq.com')) { $mail->Host = "smtp.qq.com"; // SMTP 服务器 } elseif (strpos($posterFromEmail, '139.com')) { $mail->Host = "smtp.139.com"; // SMTP 服务器 } $mail->SMTPSecure = "ssl"; //目前规定必须使用ssl,非ssl的协议已经不支持了 $mail-> Port = 465; //端口号 $mail->SMTPDebug = 2; //用于debug PHPMailer信息 $mail->SMTPAuth = true; //启用smtp认证 $mail->Username = $posterFromEmail; // 用户名 $mail->Password = $posterFromPwd; // 密码 $mail->From = $posterFromEmail; //发件人地址(也就是你的邮箱地址) $mail->FromName = "admin"; //发件人姓名 $mail->AddAddress($address); //收件人地址 $mail->WordWrap = 50; //设置每行字符长度 $mail->IsHTML(true); // 是否HTML格式邮件 $mail->CharSet="utf-8"; //设置邮件编码 $mail->Subject =$subject; //邮件主题 $mail->Body = $body; //邮件内容 $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $status = $mail->Send(); $error = $mail->ErrorInfo; if(!$status) { return $error;//发送失败 } else { return true;//发送成功 } } ~~~

正文结束

PHP接口(interface)和抽象类(abstract) php开启调试模式