mail.php 2.3 KB

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