]> source.dussan.org Git - nextcloud-server.git/commitdiff
new OC_Mail class to handle all mail sending. The benefit is that is way mor flexible...
authorFrank Karlitschek <karlitschek@kde.org>
Fri, 20 Apr 2012 18:49:35 +0000 (20:49 +0200)
committerFrank Karlitschek <karlitschek@kde.org>
Fri, 20 Apr 2012 18:49:35 +0000 (20:49 +0200)
config/config.sample.php
core/lostpassword/index.php
lib/mail.php [new file with mode: 0644]

index 199c9248c5154d02d14fe11e60cd297ce38f44f1..9f6d674fc0e4c68887ac8968bd4b6c362d511789 100755 (executable)
@@ -19,6 +19,11 @@ $CONFIG = array(
 "knowledgebaseurl" => "",
 "appstoreenabled" => true,
 "appstoreurl" => "",
+"mail_smtpmode" => "sendmail",
+"mail_smtphost" => "127.0.0.1",
+"mail_smtpauth" => "false",
+"mail_smtpname" => "",
+"mail_smtppassword" => "",
 // "datadirectory" => ""
 );
 ?>
index 89bb6cfa794ec07fde85792fe561122089901548..b6cdd601d663f4556c1f76aef5ac4a024209ae62 100644 (file)
@@ -22,7 +22,10 @@ if (isset($_POST['user'])) {
                        $msg = $tmpl->fetchPage();
                        $l = OC_L10N::get('core');
                        $from = 'lostpassword-noreply@' . $_SERVER['HTTP_HOST'];
-                       mail($email, $l->t('Owncloud password reset'), $msg, 'From:' . $from);
+                       $r=mail($email, $l->t('Owncloud password reset'), $msg, 'From:' . $from);
+//if($r==false) echo('error'); else echo('works!!!!!!!');
+                       OC_MAIL::send($email,$_POST['user'],$l->t('Owncloud password reset'),$msg,$from,'ownCloud');
+
                }
                OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => true));
        } else {
diff --git a/lib/mail.php b/lib/mail.php
new file mode 100644 (file)
index 0000000..0045f8d
--- /dev/null
@@ -0,0 +1,116 @@
+<?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' );
+               $SMTPAUTH = OC_Config::getValue( 'mail_smtpauth', 'false' ); 
+               $SMTPUSERNAME = OC_Config::getValue( 'mail_smtpname', '' ); 
+               $SMTPPASSWORD = OC_Config::getValue( 'mail_smtppassword', '' );  
+
+
+               $mailo = new PHPMailer();
+               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);
+               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);
+
+               OC_Log::write('Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject,'mail',OC_Log::DEBUG);
+
+       }
+
+
+
+       /**
+        * sending a mail based on a template
+        *
+        * @param texttemplate $texttemplate
+        * @param htmltemplate $htmltemplate
+        * @param data $data
+        * @param To $toaddress
+        * @param ToName $toname
+        * @param Subject $subject
+        * @param From $fromaddress
+        * @param FromName $fromname
+        * @param ccaddress $ccaddress
+        * @param ccname $ccname
+        * @param bcc $bcc
+        */
+       public static function getfooter() {
+
+               $txt="\n--\n";
+               $txt.="ownCloud\n";
+               $txt.="Your Cloud, Your Data, Your Way!\n";
+               return($txt);
+
+       }
+
+
+
+}