You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Frank Karlitschek <frank@owncloud.org>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. /**
  9. * OC_Mail
  10. *
  11. * A class to handle mail sending.
  12. */
  13. require_once 'class.phpmailer.php';
  14. class OC_Mail {
  15. /**
  16. * send an email
  17. *
  18. * @param string $toaddress
  19. * @param string $toname
  20. * @param string $subject
  21. * @param string $mailtext
  22. * @param string $fromaddress
  23. * @param string $fromname
  24. * @param bool|int $html
  25. * @param string $altbody
  26. * @param string $ccaddress
  27. * @param string $ccname
  28. * @param string $bcc
  29. * @throws Exception
  30. */
  31. public static function send($toaddress,$toname,$subject,$mailtext,$fromaddress,$fromname,$html=0,$altbody='',$ccaddress='',$ccname='', $bcc='') {
  32. $SMTPMODE = OC_Config::getValue( 'mail_smtpmode', 'sendmail' );
  33. $SMTPHOST = OC_Config::getValue( 'mail_smtphost', '127.0.0.1' );
  34. $SMTPPORT = OC_Config::getValue( 'mail_smtpport', 25 );
  35. $SMTPAUTH = OC_Config::getValue( 'mail_smtpauth', false );
  36. $SMTPAUTHTYPE = OC_Config::getValue( 'mail_smtpauthtype', 'LOGIN' );
  37. $SMTPUSERNAME = OC_Config::getValue( 'mail_smtpname', '' );
  38. $SMTPPASSWORD = OC_Config::getValue( 'mail_smtppassword', '' );
  39. $SMTPDEBUG = OC_Config::getValue( 'mail_smtpdebug', false );
  40. $SMTPTIMEOUT = OC_Config::getValue( 'mail_smtptimeout', 10 );
  41. $SMTPSECURE = OC_Config::getValue( 'mail_smtpsecure', '' );
  42. $mailo = new PHPMailer(true);
  43. if($SMTPMODE=='sendmail') {
  44. $mailo->IsSendmail();
  45. }elseif($SMTPMODE=='smtp') {
  46. $mailo->IsSMTP();
  47. }elseif($SMTPMODE=='qmail') {
  48. $mailo->IsQmail();
  49. }else{
  50. $mailo->IsMail();
  51. }
  52. $mailo->Host = $SMTPHOST;
  53. $mailo->Port = $SMTPPORT;
  54. $mailo->SMTPAuth = $SMTPAUTH;
  55. $mailo->SMTPDebug = $SMTPDEBUG;
  56. $mailo->SMTPSecure = $SMTPSECURE;
  57. $mailo->AuthType = $SMTPAUTHTYPE;
  58. $mailo->Username = $SMTPUSERNAME;
  59. $mailo->Password = $SMTPPASSWORD;
  60. $mailo->Timeout = $SMTPTIMEOUT;
  61. $mailo->From = $fromaddress;
  62. $mailo->FromName = $fromname;;
  63. $mailo->Sender = $fromaddress;
  64. $a=explode(' ', $toaddress);
  65. try {
  66. foreach($a as $ad) {
  67. $mailo->AddAddress($ad, $toname);
  68. }
  69. if($ccaddress<>'') $mailo->AddCC($ccaddress, $ccname);
  70. if($bcc<>'') $mailo->AddBCC($bcc);
  71. $mailo->AddReplyTo($fromaddress, $fromname);
  72. $mailo->WordWrap = 50;
  73. if($html==1) $mailo->IsHTML(true); else $mailo->IsHTML(false);
  74. $mailo->Subject = $subject;
  75. if($altbody=='') {
  76. $mailo->Body = $mailtext.OC_MAIL::getfooter();
  77. $mailo->AltBody = '';
  78. }else{
  79. $mailo->Body = $mailtext;
  80. $mailo->AltBody = $altbody;
  81. }
  82. $mailo->CharSet = 'UTF-8';
  83. $mailo->Send();
  84. unset($mailo);
  85. OC_Log::write('mail', 'Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject, OC_Log::DEBUG);
  86. } catch (Exception $exception) {
  87. OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR);
  88. throw($exception);
  89. }
  90. }
  91. /**
  92. * return the footer for a mail
  93. *
  94. */
  95. public static function getfooter() {
  96. $txt="\n--\n";
  97. $txt.="ownCloud\n";
  98. $txt.="Your Cloud, Your Data, Your Way!\n";
  99. return($txt);
  100. }
  101. }