当我们要做邮箱考证码的时辰,应用此外第三方的邮件smtp,举行邮件发送会出现用户收不到邮件,或收到邮件会很慢,而阿里云邮件推送的功能能够打点,稳定及时的发送邮件给客户,
起首在阿里云邮件推送设置一个域名
再到域名那边剖析以下:
剖析乐成后严格经由过程后就能够写法式
https://github.com/aliyun/openapi-sdk-php
在这个地点下载php sdk
vendor('sdk.vendor.autoload');
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\NlsCloudMeta\NlsCloudMeta;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
引入sdk文件
vendor('sdk.vendor.autoload');
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\NlsCloudMeta\NlsCloudMeta;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
class AliyunemailService {
function __construct() {
// $fwconfig = D('Config')->getAll();
$config = array(
'MAIL_CHARSET' => 'UTF-8',
'MAIL_SMTPAUTH' => true, //是否是应用身份考证
'MAIL_ISHTML' => true, //是否是应用html
'MAIL_USERNAME' => '', //发件地点
// 'MAIL_USERNAME' => 'send3@szfangwei.cn', //发件地点
'MAIL_SMTPHOST' => '', //smtp地点
'MAIL_PASSWORD' => '', //发件地点暗码
'MAIL_GET_ADDRESS' => '', //默许收件箱
);
$this->mailconfig = $config;
}
/**
* 发送邮件
* @param $get_email
* @param $data array('title'=>'','title2'=>'','detail'=>'')
* @return bool
*/
public function sendEmail($data, $get_email = '') {
$mail = $this->setBaseConfig($data, $get_email);
return $mail;
}
/**
* 邮件底子设置
* @param $mail
* @param $data
* @param string $get_email
* @return mixed
*/
public function setBaseConfig($data, $get_email = '') {
AlibabaCloud::accessKeyClient('LTAImdH845znjHst', 'Vsimrg02TDW1wrM100LvvEbGtrGu6S')
->regionId('cn-hangzhou')
->asDefaultClient();
try {
$result = AlibabaCloud::rpc()
->product('Dm')
// ->scheme('https') // https | http
->version('2015-11-23')
->action('SingleSendMail')
->method('POST')
->host('dm.aliyuncs.com')
->options([
'query' => [
'RegionId' => "cn-hangzhou",
'AccountName' => "",//发件人
'AddressType' => "1",
'ReplyToAddress' => "false",
'ToAddress' => $get_email,//收件人
'Subject' => $data['title'],
'TagName' => "tag",//不消管
'HtmlBody' => $data['detail'],//发送html格局的内容
'TextBody' => "",//发送文本内容
'FromAlias' => $data['title2'],//发件人昵称
'ReplyAddress' => "",//回件邮箱
'ReplyAddressAlias' => "客户",//不消管
'ClickTrace' => "0",
&nbs