Step: 1 Create the form
<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">
<input type="text" name="emailid" id="emailid" />
<input type="text" name="subject" id="subject" />
<input type="text" name="message" id="message" />
<input type="file" name="attachment" id="attachment" />
</form>
Step: 2 Get the form value and Call the mail function
$recipient = JRequest::getVar('emailid', '', 'post', 'string', JREQUEST_ALLOWRAW);
$subject = JRequest::getVar('subject', '', 'post', 'string', JREQUEST_ALLOWRAW);
$body = JRequest::getVar('message', '', 'post', 'string', JREQUEST_ALLOWRAW);
$attachment = JRequest::getVar('attachment', null, 'files', 'array');
$attachmentname=$attachment[name];
jimport( 'joomla.utilities.utility' );
JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=null, $bcc=null, $attachment, $attachmentname, $replyto=null, $replytoname=null);
Step: 3 Replace the function "addAttachment" in libraries/joomla/mail.php
function addAttachment($attachment, $name = '')
{
// If the file attachments is an aray, add each file... otherwise just add the one
if (isset ($attachment))
{
if (is_array($attachment)) {
foreach ($attachment as $file) {
parent::AddAttachment($file, $name);
}
}
else
{
parent::AddAttachment($attachment, $name);
}
}
}
Step: 4 Replace the below code in ( libraries\joomla\utilities\utility.php ) line 44
function sendMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=null, $bcc=null, $attachment=null,$attachmentname, $replyto=null, $replytoname=null )
No comments:
Post a Comment