/
helper.php
executable file
·77 lines (67 loc) · 2.48 KB
/
helper.php
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
73
74
75
76
77
<?php
// No direct access
defined('JPATH_PLATFORM') or die;
/**
* Helper class for JCallback module
*
* @package Joomla.Site
* @subpackage mod_jcallback
*/
class ModJcallbackHelper
{
/**
* Check the $_POST vars
*
* @param array $params An object containing the module parameters
*
* @access public
*/
public static function check($params)
{
if(JRequest::getVar('jcallback')){
self::sendMail($params);
}
}
/**
* Send email whith user data from form
*
* @param array $params An object containing the module parameters
*
* @access public
*/
public static function sendMail($params)
{
$sender = $params->get('sender');
$recipient = $params->get('recipient');
$subject = $params->get('subject');
// Getting the site name
$sitename = JFactory::getApplication()->get('sitename');
// Getting user form data-------------------------------------------------
$name = JFilterInput::getInstance()->clean(JRequest::getVar('name'));
$phone = JFilterInput::getInstance()->clean(JRequest::getVar('phone'));
$email = JFilterInput::getInstance()->clean(JRequest::getVar('email'));
$message = JFilterInput::getInstance()->clean(JRequest::getVar('message'));
// Set the massage body vars
$nameLabel = JText::_('MOD_JCALLBACK_FORM_NAME_LABEL_VALUE');
$phoneLabel = JText::_('MOD_JCALLBACK_FORM_PHONE_LABEL_VALUE');
$emailLabel = JText::_('MOD_JCALLBACK_FORM_EMAIL_LABEL_VALUE');
$messageLabel = JText::_('MOD_JCALLBACK_FORM_MESSAGE_LABEL_VALUE');
$emailLabel = $email ? "<b>$emailLabel:</b> $email" : "";
$messageLabel = $message ? "<b>$messageLabel:</b> $message" : "";
// Get the JMail ogject
$mailer = JFactory::getMailer();
// Set JMail object params------------------------------------------------
$mailer->setSubject($subject);
$params->get('useSiteMailfrom') ?
$mailer->setSender(JFactory::getConfig()->get( 'mailfrom' )) :
$mailer->setSender($sender);
$mailer->addRecipient($recipient);
// Get the mail message body
require JModuleHelper::getLayoutPath('mod_jcallback','default_email_message');
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
$mailer->Send();
// The mail sending errors will be shown in the Joomla Warning Message from JMail object..
}
}