首先,在thinkphp项目目录执行:
composer require gclinux/smtper
然后,在你需要发邮件的地方加入下面代码$mail = new gclinux\Smtper();
$mail->setServer("smtp.XXX.COM", "your_acount@XXXXX", "passwd"); //Setting the SMTP server without SSL. 无SSL的SMTP服务器设置
//$mail->setServer("XXXXX", "joffe@XXXXX", "XXXXX", 465, true);//Seeting the SMTP server with SSL .SSL的SMTP服务器设置
$mail->setFrom("XXXXX"); //Email Sender name 发送者
$mail->setReceiver("XXXXX@local"); //Email reciver 接收者
$mail->addAttachment("XXXX.png"); //Attachment 附件
$mail->setMail("title ", "<b>body</b>"); //the titile and body 标题和内容
$mail->send();
详细查看githubhttps://github.com/gclinux/smtper