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的写法。

  • 相关阅读:
    IDA断点和搜索
    shell grep正则匹配汉字
    吐槽一下jsoup
    mysql函数
    hutools之批量更新
    Hutools之http工具类
    Java通过腾讯邮箱发送邮件
    访问网络资源的方式--application/json和x-www-form-urlencoded
    HttpClient获取数据
    URLConnection类的使用
  • 原文地址:https://www.cnblogs.com/freephp/p/12215311.html
Copyright © 2011-2022 走看看