blob: 0564237716572c487c0f23c88638e56bcaa29883 [file] [log] [blame]
<?php
require_once "Mail.php";
include('Mail/mime.php');
include 'config.php';
include_once 'User.php';
use \User as User;
function send_mail(string $email, object $smtp, object $message, User $user = null) {
include 'config.php';
$crlf = "\r\n";
$headers = array(
'From' => $smtp->from,
'To' => $email,
'Subject' => $message->subject
);
if (isset($CC_MAIL)) {
$headers['Cc'] = $CC_MAIL;
$email .= ', ' . $CC_MAIL;
}
if (isset($BCC_MAIL)) {
$email .= ', ' . $BCC_MAIL;
}
$smtp = Mail::factory('smtp', array(
'host' => $smtp->host,
'port' => $smtp->port,
'auth' => true,
'username' => $smtp->username, //your gmail account
'password' => $smtp->password // your password
));
// Creating the Mime message
$mime = new Mail_mime(array(
"text_charset" => "utf-8",
"html_charset" => "utf-8",
"eol" => $crlf
));
// Setting the body of the email
$mime->setTXTBody($message->text);
$mime->setHTMLBody($message->html);
if ($user && $user->invoice) {
$mime->addAttachment ( $user->invoice , 'application/pdf' , "invoice-".$SERVICE_ACRONYM."-" . $user->id . ".pdf" , false, "base64" );
}
$body = $mime->get();
$headers = $mime->headers($headers);
// Send the mail
$mail = $smtp->send($email, $headers, $body);
//check mail sent or not
if (PEAR::isError($mail)) {
return false;
} else {
return true;
}
}
/* send_mail("mattf@tilde.club", $SMTP, (object) [ */
/* "subject" => "Please confirm your email", */
/* "text" => "Plain tet", */
/* "html" => "<html><body><p>HTML message</p><h2>This is not mere text</h2></body></html>" */
/* ]) */
?>