DEMO: Mail/Send - 郵件發(fā)送
代碼示例
<?php
/*****************
* 非加密請(qǐng)求 示例代碼
******************/
//appid參數(shù) appkey參數(shù)在 短信-創(chuàng)建/管理AppID中獲取
//附件地址 : 本機(jī)內(nèi)文件地址
$appid = '6***3'; //appid參數(shù)
$appkey = '5d****************************58'; //appkey參數(shù)
$attachments = curl_file_create('/Users/duan/Desktop/1.png'); //附件地址
$subject = '郵件主題'; //郵件主題
$from = 'from@domain.com'; //發(fā)送人 郵箱
$to = 'to@domain.com'; //接收人 地址
$html = '<body>郵件內(nèi)容...</body>'; //郵件內(nèi)容
$post_data = array(
"appid" => $appid,
"signature" => $appkey,
"attachments" => $attachments,
"subject" => $subject,
"from" => $from,
"to" => $to,
"html" => $html,
);
$ch = curl_init();
curl_setopt_array($ch , array(
CURLOPT_URL => 'https://api-v4.mysubmail.com/mail/send.json',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1 ,
CURLOPT_POSTFIELDS => $post_data
));
$output = curl_exec($ch);
curl_close($ch);
echo json_encode($output);
/*****************
* 加密請(qǐng)求 示例代碼
******************/
//appid參數(shù) appkey參數(shù)在 短信-創(chuàng)建/管理AppID中獲取
//附件地址 : 本機(jī)內(nèi)文件地址
$appid = '6***3'; //appid參數(shù)
$appkey = '5d****************************58'; //appkey參數(shù)
$attachments = curl_file_create('/Users/duan/Desktop/1.png'); //附件地址
$subject = '郵件主題'; //郵件主題
$from = 'from@domain.com'; //發(fā)送人 郵箱
$to = 'to@domain.com'; //接收人 地址
$html = '<body>郵件內(nèi)容...</body>'; //郵件內(nèi)容
//通過(guò)接口,獲取時(shí)間戳
$ch = curl_init();
curl_setopt_array($ch , array(
CURLOPT_URL => 'https://api-v4.mysubmail.com/service/timestamp.json' ,
CURLOPT_RETURNTRANSFER => 1 ,
CURLOPT_POST => 0 ,
));
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
$timestamp = $output['timestamp'];
$post_data = Array (
"appid" => $appid,
"attachments" => $attachments,
"subject" => $subject,
"from" => $from,
"to" => $to,
"html" => $html,
"sign_version" => 2,
"sign_type" => 'md5',
"timestamp" => $timestamp,
);
$temp = $post_data;
unset($temp['attachments']);
unset($temp['html']);
ksort($temp);
reset($temp);
$tempStr = "";
foreach ($temp as $key => $value) {
$tempStr.=$key."=".$value."&";
}
$tempStr = substr($tempStr,0,-1);
//生成簽名
$post_data['signature'] = md5($appid.$appkey.$tempStr.$appid.$appkey);
$ch = curl_init();
curl_setopt_array($ch , array(
CURLOPT_URL => 'https://api-v4.mysubmail.com/mail/send.json' ,
CURLOPT_RETURNTRANSFER => 1 ,
CURLOPT_POST => 1 ,
CURLOPT_POSTFIELDS => $post_data ,
));
$output = curl_exec($ch);
curl_close($ch);
echo json_encode($output);