2012-04-20 22:49:35 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Frank Karlitschek <frank@owncloud.org>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OC_Mail
|
|
|
|
*
|
|
|
|
* A class to handle mail sending.
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once('class.phpmailer.php');
|
|
|
|
|
|
|
|
class OC_Mail {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send an email
|
|
|
|
*
|
|
|
|
* @param string $toaddress
|
|
|
|
* @param string $toname
|
|
|
|
* @param string $subject
|
|
|
|
* @param string $mailtext
|
|
|
|
* @param string $fromaddress
|
|
|
|
* @param string $fromname
|
|
|
|
* @param bool $html
|
|
|
|
*/
|
|
|
|
public static function send($toaddress,$toname,$subject,$mailtext,$fromaddress,$fromname,$html=0,$altbody='',$ccaddress='',$ccname='',$bcc='') {
|
|
|
|
|
|
|
|
$SMTPMODE = OC_Config::getValue( 'mail_smtpmode', 'sendmail' );
|
|
|
|
$SMTPHOST = OC_Config::getValue( 'mail_smtphost', '127.0.0.1' );
|
2012-05-31 23:28:58 +04:00
|
|
|
$SMTPAUTH = OC_Config::getValue( 'mail_smtpauth', false );
|
2012-04-20 22:49:35 +04:00
|
|
|
$SMTPUSERNAME = OC_Config::getValue( 'mail_smtpname', '' );
|
|
|
|
$SMTPPASSWORD = OC_Config::getValue( 'mail_smtppassword', '' );
|
|
|
|
|
|
|
|
|
2012-07-11 23:52:51 +04:00
|
|
|
$mailo = new PHPMailer(true);
|
2012-04-20 22:49:35 +04:00
|
|
|
if($SMTPMODE=='sendmail') {
|
|
|
|
$mailo->IsSendmail();
|
|
|
|
}elseif($SMTPMODE=='smtp'){
|
|
|
|
$mailo->IsSMTP();
|
|
|
|
}elseif($SMTPMODE=='qmail'){
|
|
|
|
$mailo->IsQmail();
|
|
|
|
}else{
|
|
|
|
$mailo->IsMail();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$mailo->Host = $SMTPHOST;
|
|
|
|
$mailo->SMTPAuth = $SMTPAUTH;
|
|
|
|
$mailo->Username = $SMTPUSERNAME;
|
|
|
|
$mailo->Password = $SMTPPASSWORD;
|
|
|
|
|
|
|
|
$mailo->From =$fromaddress;
|
|
|
|
$mailo->FromName = $fromname;;
|
|
|
|
$a=explode(' ',$toaddress);
|
2012-07-11 23:36:27 +04:00
|
|
|
try {
|
|
|
|
foreach($a as $ad) {
|
|
|
|
$mailo->AddAddress($ad,$toname);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($ccaddress<>'') $mailo->AddCC($ccaddress,$ccname);
|
|
|
|
if($bcc<>'') $mailo->AddBCC($bcc);
|
|
|
|
|
|
|
|
$mailo->AddReplyTo($fromaddress, $fromname);
|
|
|
|
|
|
|
|
$mailo->WordWrap = 50;
|
|
|
|
if($html==1) $mailo->IsHTML(true); else $mailo->IsHTML(false);
|
|
|
|
|
|
|
|
$mailo->Subject = $subject;
|
|
|
|
if($altbody=='') {
|
|
|
|
$mailo->Body = $mailtext.OC_MAIL::getfooter();
|
|
|
|
$mailo->AltBody = '';
|
|
|
|
}else{
|
|
|
|
$mailo->Body = $mailtext;
|
|
|
|
$mailo->AltBody = $altbody;
|
|
|
|
}
|
|
|
|
$mailo->CharSet = 'UTF-8';
|
|
|
|
|
|
|
|
$mailo->Send();
|
|
|
|
unset($mailo);
|
2012-07-11 23:41:59 +04:00
|
|
|
OC_Log::write('mail', 'Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject, OC_Log::DEBUG);
|
2012-07-11 23:36:27 +04:00
|
|
|
} catch (Exception $exception) {
|
|
|
|
OC_Log::write('mail', $exception->getMessage(), OC_Log::DEBUG);
|
2012-04-20 22:49:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-06-06 16:18:30 +04:00
|
|
|
* return the footer for a mail
|
2012-04-20 22:49:35 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getfooter() {
|
|
|
|
|
|
|
|
$txt="\n--\n";
|
|
|
|
$txt.="ownCloud\n";
|
|
|
|
$txt.="Your Cloud, Your Data, Your Way!\n";
|
|
|
|
return($txt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|