zoukankan      html  css  js  c++  java
  • WordPress使用PHPMailer发送gmail邮件

    wordpress使用phpmailer发送gmail邮件

    • 0.保证用于gmail账号已经开启imap服务,且你能正常访问到gmail的smtp服务。(需要climb over the wall)

    • 1.引入phpmailer相关类

    原来在wp-includes里面有class-phpmailer.php和class-smtp.php两个文件,可以把它们拷贝到你需要编写发送邮件的那个文件的同级目录。然后引入代码如下:

    include("class-phpmailer.php");
    include("class-smtp.php");
    
    • 2.设置phpmailer配置
    $mail = new PHPMailer();
    $body = "Hi, my friend, just a test for audience! from ssr@interbrands.com";
    $mail->IsSMTP();
    $mail->Host = "smtp.gmail.com";
    $mail->SMTPDebug = 2;
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "tls";
    $mail->Port = 587;
    

    特别注意,要使用tls,而不是ssl。端口号为587,host为smtp.gmail.com。调试阶段可以设置SMTPDebug,否则应该删掉或者屏蔽这行的设置。

    • 3.设置发送内容
    $mail->Username = "fightforphp@gmail.com";
    $mail->Password = "xxxxxxx";
    
    $body = "This is a test message not in awe of creation."; // 邮件内容
    $mail->setFrom('fightforphp@mail.com', 'HelpForEmail');
    $mail->Subject = 'Ask for help now'; // 邮件主题
    $mail->msgHTML($body);
    $mail->CharSet = "utf-8";
    $address = "xxx@gmail.com";
    $mail->addAddress($address);
    

    关键不在于怎么用PHPMailer,关键在于当我们处于某种特定技术框架下怎么样写出具有good smell 和 particular的写法。

  • 相关阅读:
    mui-app 拍照、视频、图片选择,自动上传
    vue table大屏自动刷新滚动效果
    ant-design vue table表格高亮某一行 某一格
    vue-cli@3 ht 引入使用
    JAVA匿名内部类
    JAVA基本类型和引用类型
    引用 IO流学习详细教程
    JAVA多态
    JAVA数据类型能串门不?
    JAVA基本数据类型
  • 原文地址:https://www.cnblogs.com/freephp/p/12215311.html
Copyright © 2011-2022 走看看