1、生成长度为$length 的编码串:
public function generateCode($length)
{
$randomId = crypt(uniqid(rand(), 1));
$randomId = str_replace('.', '', $randomId);
$randomId = strrev(str_replace('/', '', $randomId));
$randomId = substr($randomId, 0, $length);
return $randomId;
}
2、smtp 发送邮件:
function sendEmail($toEmail, $subject, $message){ $mail = new Mail(); $mail->protocol = $config->get('mail_protocol'); $mail->parameter = $config->get('mail_parameter'); $mail->hostname = $config->get('smtp_host'); $mail->username = $config->get('smtp_username'); $mail->password = $config->get('smtp_password'); $mail->port = $config->get('smtp_port'); $mail->timeout = $config->get('smtp_timeout'); $mail->setTo($toEmail); $mail->setFrom($config->get('email')); $mail->setSender('Xuehonghu'); $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8')); $mail->setHtml($message); $mail->send(); }
3、使用Ums接口发送Email
$url = 'http://sysmail.fagms.net/cgi-bin/systemmail-utf8?ACTION=SYSTEM&email=rest3%40163.com&gender=female&lastname=&firstname=&AID=47807&mailpriority=f&mailtype=newsletter_subscription';
//AID:模版ID
$return = curlForEmail($url);
public function curlForEmail($url){
$parse = parse_url($url);
$params=array();
parse_str($parse['query'],$params);
$initurl = $parse['scheme']."://".$parse['host'].$parse['path']."?ACTION=".$params['ACTION'];
list($urlpre, $postfield) = explode('?ACTION='.$params['ACTION'].'&' , $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $initurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded;charset="UTF-8"'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$result= curl_exec ($ch);
$info= curl_getinfo($ch);
curl_close ($ch);
return array('result'=>$result, 'info'=>$info);
}