2012-04-20 18:49:35 +00: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.
|
|
|
|
*/
|
|
|
|
|
2012-09-05 21:28:59 +00:00
|
|
|
require_once 'class.phpmailer.php';
|
2012-04-20 18:49:35 +00:00
|
|
|
|
|
|
|
class OC_Mail {
|
|
|
|
|
|
|
|
/**
|
2012-08-29 06:38:33 +00:00
|
|
|
* send an email
|
2012-04-20 18:49:35 +00:00
|
|
|
*
|
|
|
|
* @param string $toaddress
|
|
|
|
* @param string $toname
|
|
|
|
* @param string $subject
|
|
|
|
* @param string $mailtext
|
|
|
|
* @param string $fromaddress
|
|
|
|
* @param string $fromname
|
2013-01-02 18:04:08 +00:00
|
|
|
* @param bool|int $html
|
|
|
|
* @param string $altbody
|
|
|
|
* @param string $ccaddress
|
|
|
|
* @param string $ccname
|
|
|
|
* @param string $bcc
|
|
|
|
* @throws Exception
|
2012-04-20 18:49:35 +00:00
|
|
|
*/
|
2012-11-04 10:10:46 +00:00
|
|
|
public static function send($toaddress,$toname,$subject,$mailtext,$fromaddress,$fromname,$html=0,$altbody='',$ccaddress='',$ccname='', $bcc='') {
|
2012-04-20 18:49:35 +00:00
|
|
|
|
|
|
|
$SMTPMODE = OC_Config::getValue( 'mail_smtpmode', 'sendmail' );
|
|
|
|
$SMTPHOST = OC_Config::getValue( 'mail_smtphost', '127.0.0.1' );
|
2013-01-02 18:04:08 +00:00
|
|
|
$SMTPPORT = OC_Config::getValue( 'mail_smtpport', 25 );
|
2012-08-29 06:38:33 +00:00
|
|
|
$SMTPAUTH = OC_Config::getValue( 'mail_smtpauth', false );
|
|
|
|
$SMTPUSERNAME = OC_Config::getValue( 'mail_smtpname', '' );
|
|
|
|
$SMTPPASSWORD = OC_Config::getValue( 'mail_smtppassword', '' );
|
2012-04-20 18:49:35 +00:00
|
|
|
|
|
|
|
|
2012-07-11 19:52:51 +00:00
|
|
|
$mailo = new PHPMailer(true);
|
2012-04-20 18:49:35 +00:00
|
|
|
if($SMTPMODE=='sendmail') {
|
|
|
|
$mailo->IsSendmail();
|
2012-09-07 13:22:01 +00:00
|
|
|
}elseif($SMTPMODE=='smtp') {
|
2012-04-20 18:49:35 +00:00
|
|
|
$mailo->IsSMTP();
|
2012-09-07 13:22:01 +00:00
|
|
|
}elseif($SMTPMODE=='qmail') {
|
2012-04-20 18:49:35 +00:00
|
|
|
$mailo->IsQmail();
|
|
|
|
}else{
|
|
|
|
$mailo->IsMail();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$mailo->Host = $SMTPHOST;
|
2013-01-02 18:04:08 +00:00
|
|
|
$mailo->Port = $SMTPPORT;
|
2012-04-20 18:49:35 +00:00
|
|
|
$mailo->SMTPAuth = $SMTPAUTH;
|
|
|
|
$mailo->Username = $SMTPUSERNAME;
|
|
|
|
$mailo->Password = $SMTPPASSWORD;
|
|
|
|
|
|
|
|
$mailo->From =$fromaddress;
|
|
|
|
$mailo->FromName = $fromname;;
|
2012-09-04 14:13:34 +00:00
|
|
|
$mailo->Sender =$fromaddress;
|
2012-11-02 18:53:02 +00:00
|
|
|
$a=explode(' ', $toaddress);
|
2012-07-11 19:36:27 +00:00
|
|
|
try {
|
|
|
|
foreach($a as $ad) {
|
2012-11-02 18:53:02 +00:00
|
|
|
$mailo->AddAddress($ad, $toname);
|
2012-07-11 19:36:27 +00:00
|
|
|
}
|
|
|
|
|
2012-11-02 18:53:02 +00:00
|
|
|
if($ccaddress<>'') $mailo->AddCC($ccaddress, $ccname);
|
2012-07-11 19:36:27 +00:00
|
|
|
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 19:41:59 +00:00
|
|
|
OC_Log::write('mail', 'Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject, OC_Log::DEBUG);
|
2012-07-11 19:36:27 +00:00
|
|
|
} catch (Exception $exception) {
|
2012-07-29 22:01:43 +00:00
|
|
|
OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR);
|
|
|
|
throw($exception);
|
2012-04-20 18:49:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-06 12:18:30 +00:00
|
|
|
* return the footer for a mail
|
2012-04-20 18:49:35 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getfooter() {
|
|
|
|
|
|
|
|
$txt="\n--\n";
|
|
|
|
$txt.="ownCloud\n";
|
|
|
|
$txt.="Your Cloud, Your Data, Your Way!\n";
|
|
|
|
return($txt);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|