MailSendDemo
代码示列
<?php
$appid = "";
$appkey = "";
$from = "from@domain.com";
$to = "to@domain.com";
$attachments = "/Users/duan/Desktop/1.png";
$version = "2";
$sign_type = "md5";
if($sign_type != "md5" && $sign_type != "sha1"){
$post_data = Array
(
"appid" => $appid,
"signature" => $appkey,
"attachments" => curl_file_create($attachments),
"subject" => "这是来自submail的一封邮件",
"from" => $from,
"to" => $to,
"html" => "<body>您好,您的注册验证代码为ABCDEFG,请妥善保管</body>",
);
}else{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.mysubmail.com/service/timestamp.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);
$timestamp = $output['timestamp'];
$post_data = Array
(
"appid" => $appid,
"attachments" => curl_file_create($attachments),
"subject" => "这是来自submail的一封邮件",
"from" => $from,
"to" => $to,
"html" => "<body>您好,您的注册验证代码为ABCDEFG,请妥善保管</body>",
"sign_version" => $version,
"sign_type" => $sign_type,
"timestamp" => $timestamp,
);
$temp = $post_data;
if($version == '2'){
unset($temp['attachments']);
unset($temp['html']);
}else{
unset($temp['attachments']);
unset($temp['sign_version']);
}
ksort($temp);
reset($temp);
$tempStr = "";
foreach ($temp as $key => $value) {
$tempStr.=$key."=".$value."&";
}
$tempStr = substr($tempStr,0,count($tempStr)-2);
if($sign_type == "md5")
$post_data['signature'] = md5($appid.$appkey.$tempStr.$appid.$appkey);
else
$post_data['signature'] = sha1($appid.$appkey.$tempStr.$appid.$appkey);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.mysubmail.com/mail/send.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
echo json_encode($output);