1 Star 0 Fork 0

Crogram SMTPHub/SMTPHub-sdk-php

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SMTPHub.php 3.00 KB
一键复制 编辑 原始数据 按行查看 历史
Jackson 提交于 2023-09-16 17:32 +08:00 . add demo code
<?php
namespace lib\mail;
/**
* SMTPHub PHP SDK
*/
class SMTPHub
{
private $api;
private $appid;
private $appsecret;
/** 构造函数
* @param string $api 接口地址,如:https://smtphub.yourcompany.com/api.php
* @param string $appid 应用ID,如:1000
* @param string $appsecret 应用密钥,如:abcdefghijklmnopqrestuvwxyz
* @return void
*/
function __construct($api, $appid, $appsecret)
{
$this->api = $api;
$this->appid = $appid;
$this->appsecret = $appsecret;
}
/** 发送邮件
* @param string $to 收件人地址
* @param string $subject 邮件主题
* @param string $message 邮件内容
* @param string $to_name 收件人名称
* @param string $from_name 发送人名称
* @return string|bool 是否发送成功
*/
public function send($to, $subject, $message, $to_name, $from_name)
{
if (empty($this->api) || empty($this->appid) || empty($this->appsecret)) return false;
// 构造请求参数列表
$data = array(
'appid' => $this->appid,
'appsecret' => $this->appsecret,
'action' => 'send',
'to' => $to,
'to_name' => $to_name,
'subject' => $subject,
'message' => $message,
'from_name' => $from_name
);
$res = SMTPHub::curl_send($this->api, $data, 1);
return $res;
}
private function curl_send($url, $data = null, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$httpheader[] = "Accept: */*";
$httpheader[] = "Accept-Encoding: gzip,deflate,sdch";
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
$httpheader[] = "Connection: close";
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
if ($header) {
curl_setopt($ch, CURLOPT_HEADER, true);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
if ($referer) {
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
if ($ua) {
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
} else {
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.62");
}
if ($nobaody) {
curl_setopt($ch, CURLOPT_NOBODY, 1);
}
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/SMTPHub/SMTPHub-sdk-php.git
git@gitee.com:SMTPHub/SMTPHub-sdk-php.git
SMTPHub
SMTPHub-sdk-php
SMTPHub-sdk-php
main

搜索帮助