add code in joomla contact form

2019-09-08 16:52发布

问题:

Please Help me I am trying to setup attached file in send mail Joomla v3.1.5 I have set all but attached file not receiving in mail.

$strSid = md5(uniqid(time()));

$strHeader = "";
//$strHeader .= "From: ".$_POST["contact_name"]."

<".$_POST["contact_email"].">\nReply-To: ".$_POST["contact_email"]."";

$strHeader .= "MIME-Version: 1.0\n";

$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";

$strHeader .= "This is a multi-part message in MIME format.\n";

$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";


//*** Attachment ***//

    if($_FILES["filename"]["name"] != "")
{
    $strFilesName = $_FILES["filename"]["name"];
    $strContent = chunk_split(base64_encode(file_get_contents($_FILES["filename"]["tmp_name"]))); 

    $strHeader .= "--".$strSid."\n";

    $strHeader .= "Content-Type: application/octet-stream; 
name=\"".$strFilesName."\"\n"; 

    $strHeader .= "Content-Transfer-Encoding: base64\n";
    $strHeader .= "Content-Disposition: attachment; 

filename=\"".$strFilesName."\"\n\n";

    $strHeader .= $strContent."\n\n";
}
        // Prepare email body
        $prefix = JText::sprintf('COM_CONTACT_ENQUIRY_TEXT', JUri::base());
        $body   = $prefix."\n".$name.'<'.$email.'>'."\n".$filename."\r\n\r\n".stripslashes($body);

        $mail = JFactory::getMailer();
        $mail->addRecipient($contact->email_to);
        $mail->addReplyTo(array($email, $name));
        $mail->setSender(array($mailfrom, $fromname));
        $mail->setSubject($sitename.': '.$subject);
        $mail->setBody($body);

        $sent = $mail->Send();

I just need to set $strHeader variable in JFactory::getMailer(); function I think. please help me?

回答1:

There are so many good advanced contact form extensions in the JED, using one of those is going to give you so much more flexibility to do additional things. Still if you want to do this, you should do it as a plugin rather than hacking core files. Also, you don't seem to be scanning for executable extensions or to be checking for code hidden in image files.