php

简易发邮件

dafenqi
2024-06-11 / 2 评论 / 12 阅读 / 正在检测是否收录...
    /*
     * 第三方发邮件接口 https://luckycola.com.cn/public/docs/shares/api/mail.html
    {
        "ColaKey": "i6qNeQszeSD6zf16988I2YaRNIMz",// 官网获取
        "tomail": "1537@163.com",// 邮件发给谁?
        "fromTitle": "我是邮件标题",// 邮件标题
        "subject": "我是邮件主题",
        // 邮件系统授权码,参考[获取文档]:https://blog.csdn.net/qq_48896417/article/details/133903185?spm=1001.2014.3001.5501
        "smtpCode": "GNNSC*******TWU",
        // 开启授权码对应的授权邮箱
        "smtpEmail": "example@163.com",
        // 授权邮箱的类型, 可取值是 qq 或 163 或 126
        "smtpCodeType": "163",
        "isTextContent": false,// 邮件内容是否是纯文本形式
        "content": "<div style='color: red'>我是邮件内容(因为isTextContent=false所以我可以解析html标签,是红色的)</div>",// 邮件内容
    }
     */
    public function sendMail($toemail = "", $subject = "", $content = "", $fromUserInfo = "admin") {

        $params = [];
        $params["ColaKey"] = "xx";
        $params["tomail"] = $toemail;
        $params["fromTitle"] = $fromUserInfo;
        $params["subject"] = $subject;
        $params["content"] = $content;
        if (strpos($toemail,"@163") !== false) {
            $params["smtpCode"] = "xxx";//授权码有效期180天
            $params["smtpEmail"] = "xxx@163.com";
            $params["smtpCodeType"] = "163";
        } elseif (strpos($toemail,"@qq") !== false) {
            $params["smtpCode"] = "xxx";
            $params["smtpEmail"] = "xx@qq.com";
            $params["smtpCodeType"] = "qq";
        }

        $mail_url = "https://luckycola.com.cn/tools/customMail";
        $rs_str = curl($mail_url, $params);
        $rs = json_decode($rs_str,true);

        if (isset($rs["code"]) && $rs["code"] == 0) {
            $this->logfile("发送邮件成功 --> ". $rs_str);
        } else {
            $this->logfile("发送邮件失败 --> ". $rs_str);
        }

//            使用php内置mail函数发邮件,需要启动postfix服务(systemctl start postfix)且 放行外网25端口
//            ini_set("SMTP", "smtp.163.com");
//            ini_set("smtp_port", "25");

//            $tomail = "xx@qq.com"; // 收件人邮箱地址
//            $title = "邮件主题";
//            $content = "邮件内容";
//            $sendermail = "sender@example.com";
//            $headers = "From: {$sendermail}"; // 发件人邮箱地址
//
//            //发送邮件
//            $rs = mail($tomail, $title, $content, $headers);
//            if ($rs) {
//                exit("ok");
//            } else {
//                exit("邮件发送失败");
//            }

    }

// 调用    
//            $tomail = "xx@qq.com"; // 收件人邮箱地址
//            $subject = "邮件主题";
//            $content = "邮件内容";
//            $fromUserInfo = "发送方";
//            $this->sendMail($toemail, $subject, $content, $fromUserInfo);

另外稳定可用的第三方服务接口

0

Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/testblog.58heshihu.com/var/Widget/Archive.php on line 1032

评论 (2)

取消
  1. 头像
    007
    Windows 10 · Google Chrome

    Warning: Trying to access array offset on value of type null in /www/wwwroot/testblog.58heshihu.com/usr/themes/Joe-master/core/function.php on line 247
    @

    1

    回复
    1. 头像
      dafenqi 作者
      Windows 10 · Google Chrome
      @ 007

      2

      回复