mailer.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. /**
  8. * Description of mailer
  9. *
  10. * @author zongheng
  11. */
  12. class Mailer {
  13. private $emails = null, $eTitle = null, $clientName = null, $content = null;
  14. function configSendParams() {
  15. return json_encode(array('to' => array($this->emails), 'sub' => array('%eTitle%' => array($this->eTitle), '%clientName%' => array($this->clientName), '%content%' => array($this->content))));
  16. }
  17. function send_mail() {
  18. $ch = curl_init();
  19. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  21. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  22. curl_setopt($ch, CURLOPT_URL, 'https://sendcloud.sohu.com/webapi/mail.send_template.xml');
  23. curl_setopt($ch, CURLOPT_POSTFIELDS, array('api_user' => 'postmaster@websupport.sendcloud.org',
  24. 'api_key' => 'cDO1GjtY1seH',
  25. 'template_invoke_name' => 'jl_mail',
  26. 'from' => 'postmaster@zhzd.sendcloud.org',
  27. 'fromname' => '纵横计量支付云版',
  28. 'subject' => '纵横计量支付云版:' . $this->eTitle,
  29. 'substitution_vars' => $this->configSendParams()));
  30. $result = curl_exec($ch);
  31. // if ($result === false) { //请求失败
  32. // echo 'last error : ' . curl_error($ch);
  33. // }
  34. curl_close($ch);
  35. return $result;
  36. }
  37. function setEmails($emails) {
  38. $this->emails = $emails;
  39. }
  40. function seteTitle($eTitle) {
  41. $this->eTitle = $eTitle;
  42. }
  43. function setClientName($clientName) {
  44. $this->clientName = $clientName;
  45. }
  46. function setContent($content) {
  47. $this->content = $content;
  48. }
  49. function send_resetpasswd_mail() {
  50. // 用户重置密码
  51. $resetPasswdConfig = array('to' => array('aboutaboy@yeah.net'), 'sub' => array('%eTitle%' => array('新帐号开通'), '%clientName%' => array('任杰'), '%content%' => array('<p>XXXX公司为你开通了计量支付云版的帐号:</p>
  52. <p>登录帐号(邮箱):<b><a href="mailto:2448457466@qq.com" target="_blank">2448457466@q<wbr>q.com</a></b></p>
  53. <p>登录密码:<b>UJN762</b></p>
  54. <p>请及时登录并修改您的个人信息及密码。</p>')));
  55. return $this->send_mail($emails, $eTitle, $clientName, $content);
  56. }
  57. }