| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage core |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
/** |
| 15 |
* Implements the e-mail sending function through the PHPMailer lib. |
| 16 |
* |
| 17 |
* @since 1.5 |
| 18 |
*/ |
| 19 |
class VBOMailServicePhpmailer implements VBOMailService |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Sends an e-mail through the pre-installed mailing system. |
| 23 |
* |
| 24 |
* @param VBOMailWrapper $mail The e-mail encapsulation. |
| 25 |
* |
| 26 |
* @return boolean True on success, false otherwise. |
| 27 |
*/ |
| 28 |
public function send(VBOMailWrapper $mail) |
| 29 |
{ |
| 30 |
$is_html = false; |
| 31 |
|
| 32 |
$content = $mail->getContent(); |
| 33 |
|
| 34 |
// check if we have an HTML document |
| 35 |
if ($mail->isHtml()) |
| 36 |
{ |
| 37 |
// wrap content into a valid HTML document |
| 38 |
$content = "<html>\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head>\n<body>$content</body>\n</html>"; |
| 39 |
|
| 40 |
$is_html = true; |
| 41 |
} |
| 42 |
|
| 43 |
// create PHPMailer |
| 44 |
$mailer = JFactory::getMailer(); |
| 45 |
|
| 46 |
// set up e-mail sender |
| 47 |
$mailer->setSender([$mail->getSenderMail(), $mail->getSenderName()]); |
| 48 |
|
| 49 |
// set up recipient |
| 50 |
$mailer->addRecipient($mail->getRecipient()); |
| 51 |
|
| 52 |
if ($mail->getReply()) |
| 53 |
{ |
| 54 |
// set up reply-to |
| 55 |
$mailer->addReplyTo($mail->getReply()); |
| 56 |
} |
| 57 |
|
| 58 |
if ($bcc = $mail->getBcc()) |
| 59 |
{ |
| 60 |
// set BCC(s) |
| 61 |
$mailer->addBcc($bcc); |
| 62 |
} |
| 63 |
|
| 64 |
// set up e-mail subject |
| 65 |
$mailer->setSubject($mail->getSubject()); |
| 66 |
|
| 67 |
// set up e-mail content |
| 68 |
$mailer->setBody($content); |
| 69 |
|
| 70 |
// set up HTML tag |
| 71 |
$mailer->isHTML($is_html); |
| 72 |
|
| 73 |
// set up attachments |
| 74 |
foreach ($mail->getAttachments() as $file) |
| 75 |
{ |
| 76 |
$mailer->addAttachment($file); |
| 77 |
} |
| 78 |
|
| 79 |
// always use Base64 encoding |
| 80 |
$mailer->Encoding = 'base64'; |
| 81 |
|
| 82 |
// send e-mail address |
| 83 |
return $mailer->Send(); |
| 84 |
} |
| 85 |
} |
| 86 |
|