WordPress建站时不使用插件实现SMTP发送邮件的功能

前端之家收集整理的这篇文章主要介绍了WordPress建站时不使用插件实现SMTP发送邮件的功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在使用的过程当中,我们经常会用到邮件功能。WordPress 自带了 mail 函数,但用自带的 mail 函数来发送邮件的时候很容易失败或者被拒收。因此很多人选择使用更方便高效的 SMTP 来发送邮件。很多朋友都是使用插件实现 SMTP 发送邮件,如: 、 WP-Mail-SMTP。 今天我们介绍一下不使用插件来实现 SMTP 发送邮件方法

切换到主题目录,打开 functions.PHP 文件添加如下代码

Crayon-5c891d512a82f630727518" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d512a82f630727518-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d512a82f630727518-2">2
Crayon-num" data-line="Crayon-5c891d512a82f630727518-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d512a82f630727518-4">4
Crayon-num" data-line="Crayon-5c891d512a82f630727518-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d512a82f630727518-6">6
Crayon-num" data-line="Crayon-5c891d512a82f630727518-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d512a82f630727518-8">8
Crayon-num" data-line="Crayon-5c891d512a82f630727518-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d512a82f630727518-10">10
Crayon-num" data-line="Crayon-5c891d512a82f630727518-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d512a82f630727518-12">12
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d512a82f630727518-1">Crayon-t">functionCrayon-h"> Crayon-e">mail_smtpCrayon-sy">(Crayon-sy">$Crayon-v">PHPmailerCrayon-sy">)
Crayon-line Crayon-striped-line" id="Crayon-5c891d512a82f630727518-2">Crayon-sy">{
Crayon-line" id="Crayon-5c891d512a82f630727518-3">Crayon-h">Crayon-sy">$Crayon-v">PHPmailerCrayon-e">isSMTPCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d512a82f630727518-4">Crayon-h">Crayon-sy">$Crayon-v">PHPmailerCrayon-v">SMTPAuthCrayon-h"> Crayon-o">=Crayon-h"> Crayon-t">trueCrayon-sy">;Crayon-h">Crayon-c">// 启用SMTPAuth服务
Crayon-line" id="Crayon-5c891d512a82f630727518-5">Crayon-h">Crayon-sy">$Crayon-v">PHPmailerCrayon-v">PortCrayon-h"> Crayon-o">=Crayon-h"> Crayon-cn">465Crayon-sy">;Crayon-h"> Crayon-c">// SMTP邮件发送端口,常用端口有:25,安全链接端口:465、587
Crayon-line Crayon-striped-line" id="Crayon-5c891d512a82f630727518-6">Crayon-h">Crayon-sy">$Crayon-v">PHPmailerCrayon-v">SMTPSecureCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'ssl'Crayon-sy">;Crayon-h"> Crayon-c">// 是否通过SSL链接,如果端口为25,则此处将“ssl”改为空白即可'',否则不必改动
Crayon-line" id="Crayon-5c891d512a82f630727518-7">Crayon-h">Crayon-sy">$Crayon-v">PHPmailerCrayon-v">HostCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'smtp.gmail.com'Crayon-sy">;Crayon-h">Crayon-c">// SMTP服务器地址,在邮件设置或者帮助中心可以找到
Crayon-line Crayon-striped-line" id="Crayon-5c891d512a82f630727518-8">Crayon-h">Crayon-sy">$Crayon-v">PHPmailerCrayon-v">UsernameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'****@****.com'Crayon-sy">;Crayon-h"> Crayon-c">// 您的邮件地址
Crayon-line" id="Crayon-5c891d512a82f630727518-9">Crayon-h">Crayon-sy">$Crayon-v">PHPmailerCrayon-v">PasswordCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'*********'Crayon-sy">;Crayon-h"> Crayon-c">// 你的邮箱登陆密码
Crayon-line Crayon-striped-line" id="Crayon-5c891d512a82f630727518-10">Crayon-sy">}
Crayon-line" id="Crayon-5c891d512a82f630727518-11">Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d512a82f630727518-12">Crayon-e">add_actionCrayon-sy">(Crayon-s">'PHPmailer_init'Crayon-sy">,Crayon-h"> Crayon-s">'mail_smtp'Crayon-sy">)Crayon-sy">;

原文链接:https://www.f2er.com/wordpress/238515.html

猜你在找的wordpress相关文章