记录一些自定义php函数

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);

  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值