thinkPHP发送邮件
欢迎大家访问我的主页:西城Gether学习网
我的博客:浅作序
1. 使用composer安装phpmailer组件
进入Packmailer官网,搜索phpmailer组件。
在项目目录下使用命令
composer require phpmailer/phpmailer
安装组件。- 安装成功后,你就可以找到vendor/phpmailer文件夹。
在 Packmailer官网的phpmailer 页面找到:
A Simple Example
“`php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;//Load Composer’s autoloader
require ‘vendor/autoload.php’;$mail = new PHPMailer(true); // Passing
true
enables exceptions
try {
//Server settings
mail−>SMTPDebug=2;//Enableverbosedebugoutput m a i l − > S M T P D e b u g = 2 ; / / E n a b l e v e r b o s e d e b u g o u t p u t mail->isSMTP(); // Set mailer to use SMTP
mail−>Host=‘smtp1.example.com;smtp2.example.com′;//SpecifymainandbackupSMTPserver