PHP怎么利用PHPMailer实现邮件发送功能
发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,这篇文章将为大家详细讲解有关PHP怎么利用PHPMailer实现邮件发送功能,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。一、安装环境PHPMailer 需要 PH
千家信息网最后更新 2024年09月22日PHP怎么利用PHPMailer实现邮件发送功能
这篇文章将为大家详细讲解有关PHP怎么利用PHPMailer实现邮件发送功能,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
一、安装环境
PHPMailer 需要 PHP 的 sockets 扩展支持
另外登录 QQ 邮箱 SMTP 服务器则必须通过 SSL 加密的, PHP 还得包含 openssl 的支持
二、下载
地址: https://github.com/PHPMailer/PHPMailer/
三、 邮箱设置
所有的主流邮箱都支持 SMTP 协议,但并非所有邮箱都默认开启
您可以在邮箱的设置里面手动开启
第三方服务在提供了账号和密码之后就可以登录 SMTP 服务器
通过它来控制邮件的中转方式
SMTP 服务器认证密码,需要妥善保管
四、php发送邮件
SMTPDebug = 1; // 使用smtp鉴权方式发送邮件$mail->isSMTP(); // smtp需要鉴权 这个必须是true$mail->SMTPAuth = true; // 链接qq域名邮箱的服务器地址$mail->Host = 'smtp.qq.com'; // 设置使用ssl加密方式登录鉴权$mail->SMTPSecure = 'ssl'; // 设置ssl连接smtp服务器的远程服务器端口号$mail->Port = 465; // 设置发送的邮件的编码$mail->CharSet = 'UTF-8'; // 设置发件人昵称 显示在收件人邮件的发件人邮箱地址前的发件人姓名$mail->FromName = '发件人昵称'; // smtp登录的账号 任意邮箱即可$mail->Username = 'xxxxxxx@163.com'; // smtp登录的密码 使用生成的授权码$mail->Password = '**********'; // 设置发件人邮箱地址 同登录账号$mail->From = 'xxxxxxx@qq.com'; // 邮件正文是否为html编码 注意此处是一个方法$mail->isHTML(true); // 设置收件人邮箱地址$mail->addAddress('xxxxxxxxx@qq.com'); // 添加多个收件人 则多次调用方法即可$mail->addAddress('xxxxxxxxx@163.com'); // 添加该邮件的主题$mail->Subject = '邮件主题'; // 添加邮件正文$mail->Body = 'Hello, i am autofelix
'; // 为该邮件添加附件$mail->addAttachment('./附件.pdf'); // 发送邮件 返回状态$status = $mail->send();
五、php框架中使用
先使用composer进行安装:composer require phpmailer/phpmailer ^6.5
使用
SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output $mail->isSMTP(); //Send using SMTP $mail->Host = 'smtp.example.com'; //Set the SMTP server to send through $mail->SMTPAuth = true; //Enable SMTP authentication $mail->Username = 'user@example.com'; //SMTP username $mail->Password = 'secret'; //SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption $mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS` //Recipients $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient $mail->addAddress('ellen@example.com'); //Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com'); //Attachments $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name //Content $mail->isHTML(true); //Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body in bold!'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; } }}
关于"PHP怎么利用PHPMailer实现邮件发送功能"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
邮件
邮箱
服务
服务器
登录
发件人
地址
密码
收件人
方式
篇文章
账号
支持
功能
主题
方法
昵称
更多
正文
编码
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发营销策划财务分析
质量等别建数据库
怎么用web修改数据库中的内容
小程序搭配什么数据库
网络安全教育绘画海报
power bi 服务器报价
安装网络技术有什么前途
我的世界地铁模式服务器号
互联网科技创新经济论坛
以色列的网络安全性
达梦数据库日志同步
网络安全审计开源工具
数据库课程设计论文管理系统
简御宝可梦服务器地址
同花顺股票价格数据库
英灵神殿服务器设置管理员
超融合 数据库
hive如何查看外部表格数据库
如何下载安装网络安全证书
医疗软件开发上有专利证书吗
天津大型软件开发市场报价
奇迹mu+数据库+分析
数据库建表的规定
视频管理服务器的功能作用
北京苹果软件开发价格表
软件开发工程师证书算职称么
怎么用旧手机搭建内网服务器
数据库怎么创建一个学生表
mysql数据库在哪
数据库生态能力全景