mail.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 $html
  25. */
  26. public static function send($toaddress,$toname,$subject,$mailtext,$fromaddress,$fromname,$html=0,$altbody='',$ccaddress='',$ccname='',$bcc='') {
  27. $SMTPMODE = OC_Config::getValue( 'mail_smtpmode', 'sendmail' );
  28. $SMTPHOST = OC_Config::getValue( 'mail_smtphost', '127.0.0.1' );
  29. $SMTPAUTH = OC_Config::getValue( 'mail_smtpauth', false );
  30. $SMTPUSERNAME = OC_Config::getValue( 'mail_smtpname', '' );
  31. $SMTPPASSWORD = OC_Config::getValue( 'mail_smtppassword', '' );
  32. $mailo = new PHPMailer(true);
  33. if($SMTPMODE=='sendmail') {
  34. $mailo->IsSendmail();
  35. }elseif($SMTPMODE=='smtp'){
  36. $mailo->IsSMTP();
  37. }elseif($SMTPMODE=='qmail'){
  38. $mailo->IsQmail();
  39. }else{
  40. $mailo->IsMail();
  41. }
  42. $mailo->Host = $SMTPHOST;
  43. $mailo->SMTPAuth = $SMTPAUTH;
  44. $mailo->Username = $SMTPUSERNAME;
  45. $mailo->Password = $SMTPPASSWORD;
  46. $mailo->From =$fromaddress;
  47. $mailo->FromName = $fromname;;
  48. $a=explode(' ',$toaddress);
  49. try {
  50. foreach($a as $ad) {
  51. $mailo->AddAddress($ad,$toname);
  52. }
  53. if($ccaddress<>'') $mailo->AddCC($ccaddress,$ccname);
  54. if($bcc<>'') $mailo->AddBCC($bcc);
  55. $mailo->AddReplyTo($fromaddress, $fromname);
  56. $mailo->WordWrap = 50;
  57. if($html==1) $mailo->IsHTML(true); else $mailo->IsHTML(false);
  58. $mailo->Subject = $subject;
  59. if($altbody=='') {
  60. $mailo->Body = $mailtext.OC_MAIL::getfooter();
  61. $mailo->AltBody = '';
  62. }else{
  63. $mailo->Body = $mailtext;
  64. $mailo->AltBody = $altbody;
  65. }
  66. $mailo->CharSet = 'UTF-8';
  67. $mailo->Send();
  68. unset($mailo);
  69. OC_Log::write('mail', 'Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject, OC_Log::DEBUG);
  70. } catch (Exception $exception) {
  71. OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR);
  72. throw($exception);
  73. }
  74. }
  75. /**
  76. * return the footer for a mail
  77. *
  78. */
  79. public static function getfooter() {
  80. $txt="\n--\n";
  81. $txt.="ownCloud\n";
  82. $txt.="Your Cloud, Your Data, Your Way!\n";
  83. return($txt);
  84. }
  85. }