1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
<?php
/**
* This class provides methods to handle emailing
*
* @author Philipp Kiszka <info@o-dyn.de>
* @name emailer
* @package Collabtive
* @link http://www.o-dyn.de
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License v3 or later
*/
class emailer
{
private $from;
private $mailsettings;
function __construct($settings)
{
$this->mailsettings = $settings;
}
/**
* Send an email to a member
*
* @param string $to Recipient's email address
* @param string $subject Subjectline of the mail
* @param string $text Textbody of the mail, HTML allowed
* @return bool
*/
function send_mail($to, $subject, $text)
{
//create PHP Mailer object
$mailer = (object) new PHPmailer();
//setup PHPMailer
$mailer->From = $this->mailsettings["mailfrom"];
$mailer->Sender = $this->mailsettings["mailfrom"];
$mailer->FromName = $this->mailsettings["mailfromname"];
$mailer->AddAddress($to);
$mailer->Subject = $subject;
$mailer->Body = $text;
//send mail as HTML
$mailer->IsHTML(true);
//set charset
$mailer->CharSet = "utf-8";
//set mailing method... mail, smtp or sendmail
$mailer->Mailer = $this->mailsettings["mailmethod"];
//if it's smtp , set the smtp server
if($this->mailsettings["mailmethod"] == "smtp")
{
$mailer->Host = $this->mailsettings["mailhost"];
//setup SMTP auth
if($this->mailsettings["mailuser"] and $this->mailsettings["mailpass"])
{
$mailer->Username = $this->mailsettings["mailuser"];
$mailer->Password = $this->mailsettings["mailpass"];
$mailer->SMTPAuth = true;
}
}
if ($mailer->Send())
{
return true;
}
else
{
return false;
}
}
}
?>
|