mail.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. $mailo->Sender =$fromaddress;
  49. $a=explode(' ',$toaddress);
  50. try {
  51. foreach($a as $ad) {
  52. $mailo->AddAddress($ad,$toname);
  53. }
  54. if($ccaddress<>'') $mailo->AddCC($ccaddress,$ccname);
  55. if($bcc<>'') $mailo->AddBCC($bcc);
  56. $mailo->AddReplyTo($fromaddress, $fromname);
  57. $mailo->WordWrap = 50;
  58. if($html==1) $mailo->IsHTML(true); else $mailo->IsHTML(false);
  59. $mailo->Subject = $subject;
  60. if($altbody=='') {
  61. $mailo->Body = $mailtext.OC_MAIL::getfooter();
  62. $mailo->AltBody = '';
  63. }else{
  64. $mailo->Body = $mailtext;
  65. $mailo->AltBody = $altbody;
  66. }
  67. $mailo->CharSet = 'UTF-8';
  68. $mailo->Send();
  69. unset($mailo);
  70. OC_Log::write('mail', 'Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject, OC_Log::DEBUG);
  71. } catch (Exception $exception) {
  72. OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR);
  73. throw($exception);
  74. }
  75. }
  76. /**
  77. * return the footer for a mail
  78. *
  79. */
  80. public static function getfooter() {
  81. $txt="\n--\n";
  82. $txt.="ownCloud\n";
  83. $txt.="Your Cloud, Your Data, Your Way!\n";
  84. return($txt);
  85. }
  86. }