HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot//crm.jmfdbn.com/addons/saiyouems/lib/Ems.php
<?php
// +----------------------------------------------------------------------
// | Yzncms [ 御宅男工作室 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 御宅男 <530765310@qq.com>
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | 邮箱类
// +----------------------------------------------------------------------
namespace addons\saiyouems\lib;

class Ems
{
    private $_params = [];
    protected $error = '';
    protected $config = [];

    public function __construct($options = [])
    {
        if ($config = get_addon_config('saiyouems')) {
            $this->config = array_merge($this->config, $config);
        }
        $this->config = array_merge($this->config, is_array($options) ? $options : []);
    }

    /**
     * 立即发送邮件
     */
    public function send()
    {
        $this->error = '';
        $postArr = array(
            "appid" => $this->config['appid'], //用于调用access_token,接口获取授权后的access token
            "signature" => $this->config['appkey'], //申请应用时分配的AppSecret
            "from" => $this->config['from'], //发件人地址

            "to" => $this->_params['email'], //收件人地址
            "subject" => $this->_params['subject'], //邮件标题
            "text" => $this->_params['text'], //纯文本邮件正文
        );
        $options = [
            CURLOPT_HTTPHEADER => array(
                'Content-Type: application/json; charset=utf-8',
            ),
        ];
        $result = \util\Http::sendRequest('https://api.mysubmail.com/mail/send', json_encode($postArr), 'POST', $options);
        if ($result['ret']) {
            $res = (array) json_decode($result['msg'], true);
            if (isset($res['status']) && $res['status'] == 'success') {
                return true;
            }

            $this->error = isset($res['msg']) ? $res['msg'] : 'InvalidResult';
        } else {
            $this->error = $result['msg'];
        }
        return false;
    }

    /**
     * 接收邮箱
     */
    public function email($email = '')
    {
        $this->_params['email'] = $email;
        return $this;
    }

    /**
     * 邮件标题
     */
    public function subject($subject = '')
    {
        $this->_params['subject'] = $subject;
        return $this;
    }

    /**
     * 邮件标题
     */
    public function text($text = '')
    {
        $this->_params['text'] = $text;
        return $this;
    }

    /**
     * 获取错误信息
     */
    public function getError()
    {
        return $this->error;
    }

}