123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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'],
- "signature" => $this->config['appkey'],
- "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;
- }
-
- }
|