add field in joomla contact form of attach file - joomla

Please Help me i am using joomla v 3 i am trying to add field in in contact form i have set all code in joomla files but attached files not receiving? please see code below.
$filename = $data['filename'];
$name = $data['contact_name'];
$subject = $data['contact_subject'];
$body = $data['contact_message'];
$mime_boundary = "==Multipart_Boundary_x" . md5(mt_rand()) . "x";
// Now Store the file information to a variables for easier access
$tmp_name = $_FILES['filename']['tmp_name'];
$type = $_FILES['filename']['type'];
$file_name = $_FILES['filename']['name'];
$size = $_FILES['filename']['size'];
// Now here we setting up the message of the mail
$message = "\n\n Here is your file: $file_name";
if (file_exists($tmp_name)) {
if (is_uploaded_file($tmp_name)) {
$file = fopen($tmp_name, 'rb');
$data = fread($file, filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
}
$headers = "From: $body\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// Now we'll insert a boundary to indicate we're starting the attachment we have to specify the content type, file name, and disposition as an attachment, then add the file content and set another boundary to indicate that the end of the file has been reached
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$file_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
// Prepare email body
$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, $headers);
$sent = $mail->Send();
file name is receiving in body i have set but file not receiving in mail.
i have set <input type="file" name="filename"/>
please check it for me

Related

Laravel saves temp file as image

I have 3 image field for my products, on save method all working fine, but in update method first image saves temp file in database and the other two update without issue.
Code
Here I share all my 3 images on update method:
//saves temp file instead of file name
if ($request->hasFile('imageOne')) {
$imageOne = $request->file('imageOne');
$filename = 'productone' . '-' . time() . '.' . $imageOne->getClientOriginalExtension();
$location = storage_path('app/public/images/' . $filename);
Image::make($imageOne)->resize(1200, 600)->save($location);
if(!empty($product->imageOne)){
Storage::delete('images/' . $product->imageOne);
}
$product->imageOne = $imageOne;
}
//works with no issue
if ($request->hasFile('imageTwo')) {
$imageTwo = $request->file('imageTwo');
$filename = 'producttwo' . '-' . time() . '.' . $imageTwo->getClientOriginalExtension();
$location = storage_path('app/public/images/' . $filename);
Image::make($imageTwo)->resize(1200, 600)->save($location);
if(!empty($product->imageTwo)){
Storage::delete('images/' . $product->imageTwo);
}
$product->imageTwo = $filename;
}
//works with no issue
if ($request->hasFile('imageThree')) {
$imageThree = $request->file('imageThree');
$filename = 'productthree' . '-' . time() . '.' . $imageThree->getClientOriginalExtension();
$location = storage_path('app/public/images/' . $filename);
Image::make($imageThree)->resize(1200, 600)->save($location);
if(!empty($product->imageThree)){
Storage::delete('images/' . $product->imageThree);
}
$product->imageThree = $filename;
}
Any idea?
Issue is here:-
$product->imageOne = $imageOne;
You are saving $imageOne. But you need to save $filename. Use following code:-
$product->imageOne = $filename;

PHPmailer - After Form submitted the Inbox message displays HTML numeric code

The problem is with this PHP code that goes through an AJAX function and sends the content of a Form to a specific e-mail.
The essential part of the script is working, but some text appears to be converted in the Inbox when the e-mail arrives. Specifically, single-quotes (') are replaced with double-quotes (").
After searching the web and browsing SO, I couldn't find an answer. Any help would be deeply appreciated.
The code follows.
<?php
require '../config/squareconfig.php';
if($_POST)
{
//check if ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
die();
}
//check $_POST vars are set, exit if any missingc
if(!isset($_POST["usercName"]) || !isset($_POST["usercEmail"]) || !isset($_POST["usercMessage"]))
{
die();
}
//Sanitize input data using PHP filter_var().
$user_cName = filter_var($_POST["usercName"], FILTER_SANITIZE_STRING);
$user_cEmail = filter_var($_POST["usercEmail"], FILTER_SANITIZE_EMAIL);
$user_cMessage = filter_var($_POST["usercMessage"], FILTER_SANITIZE_STRING);
if(strlen($user_cName)<4) // If length is less than 4 it will throw an HTTP error.
{
header('HTTP/1.1 500 Name is too short or empty!');
exit();
}
if(!filter_var($user_cEmail, FILTER_VALIDATE_EMAIL)) //email validation
{
header('HTTP/1.1 500 Please enter a valid email!');
exit();
}
if(strlen($user_cMessage)<5) //check emtpy message
{
header('HTTP/1.1 500 Too short message! Please enter something.');
exit();
}
//proceed with PHP email.
$headers = 'From: '.$user_cEmail.' ';
$templatemail = PHP_EOL . PHP_EOL . 'User E-mail:' . PHP_EOL . $user_cEmail;
#$sentMail = mail($squarecmail, $squarecsubject, $user_cMessage . PHP_EOL . $templatemail, $user_cName);
if(!$sentMail)
{
header('HTTP/1.1 500 Could not send mail! Sorry..');
exit();
}else{
echo $squarectymessage . '<br>' . '<div class="subagain">' . $squarecontagain . '</div>';
?>
<script type="text/javascript">
$('#contact_form').fadeOut();
</script>
<?php
}
}
I'm uncertain about the "problem", but a reasonable suggestion might be to send the e-mail as HTML, since filter_var() returns html-entities for non-alphanumeric characters. Specify the content type for the e-mail message.
$headers = "From: yomama#jokes.com\r\n";
$headers .= "Reply-To: arenot#always.funny\r\n";
$headers .= "CC: yomamasobig#whenshewearsayellowcoatppleyell.taxi\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$mail_sent = #mail($sender, $subject, $message, $headers);
The above suggestion is based on the fact that FILTER_SANITIZE_STRING causes html-unicode-encoding (or some such) on the mentioned characters.
$ php-shell
PHP-Shell - Version 0.3.1, with readline() support
(c) 2006, Jan Kneschke <jan#kneschke.de>
>> echo filter_var('\' -- "', FILTER_SANITIZE_STRING);
' -- "

Cannot get SwiftMailer to Successfully Send HTML Embededd Images

When I add images to my email, SwiftMailer notifies that it has been sent, but I do not see it in my inbox, and there are not PHP errors neither.
On the other hand, without the images, the HTML, is successfully sent to my inbox. When I strip tags from the HTML message and send, I get the images alone in my inbox.
I have been dealing with this for about 3 days, and researching for a workable solution to no avail. Any help will be appreciated.
Thanks.
require_once 'Swift_Mailer/swift_required.php';
$message = Swift_Message::newInstance();
$img1 = $mail->embed( Swift_Image::fromPath( IMGFILEPATH . "img1.png" ));
$img2 = $mail->embed( Swift_Image::fromPath( IMGFILEPATH . "img2.png" ));
$subject = "To Whom It May Concern.";
$msg = "<body><div style='background:#002211; padding:10px;'><a href='" . $url . "' target='_BLANK'><img src='" . $img1 . "' id='image1' class='BORDERZERO' alt='GC' /> <img src='" . $img2 . "' id='image2' class='BORDERZERO' alt='General Collections Box.' /></a></div>";
$msg .= "<hr style='color:#555555; height:1px; background:#777777; vertical- align:top;'/><div style='padding:10px; background:#777777; color:#000000;'>";
$msg .= "<span>Hello,<br /><br />We would like to say thank you for donating to our collections box.<br /><br />The General Collections Box.<br />
$msg .= "<hr style='color:#555555; height:2px;' />";
$msg .= "If you believe that this message was sent to you in error or that you are not the intended recipient, please simply discard and disregard it. Thank you for your cooperation. - GBC.<br /></span></div></body>";
$message->setSubject( $subject )->setFrom( array( $sender => $sender_name ))
->setTo( array( $recipients ))->setBody( $html, "text/html" )
->addPart( strip_tags( $html ), "text/plain" )->setPriority( 2 )
->setReadReceiptTo( "$sender" );
if( !MMCS_Service::getSwiftMailer()->send( $mail, $failures )){
var_dump( $failures );
exit( 0 );
}

PHP mail with include template path

Trying to send a PHP email the easy way but I cannot work out why this one does not work. For some reason it sends 3 emails all with their entire content being '1' . That is all.
The PHP
else if (isset($_GET['quoteemail'])) {
$email = include(TEMPLATEPATH . '/bookings/booking-quote.php');
$to = $current_user->user_email;
$subject = "Your Order - Dive The Gap" ;
$message = $email;
$headers = "From: Dive The Gap Bookings <ask#divethegap.com>" . "\r\n" .
"Content-type: text/html" . "\r\n";
mail($to, $subject, $message, $headers);
}
Don't worry about the else if, their is an IF or 2 before this function.
Any ideas,
Marvellous
include, that includes a file and tells you "1" when it successfully includes the file.
You probably want to look into the function: file_get_contents();

PDF attachment shows up in Gmail but Outlook refuses to open it

I'm relatively new to php.
I wrote a script that sends an email with a pdf attachment to a user and a confirmation to a co-worker. Everything works fine in web-based email clients like gmail but the pdf attachment does not open when it is received in Outlook. It also adds another attachment called "ATT0159.txt" which is completely blank.
Here's the code:
<?php
$pdf = $_GET['pdf'];
$product = $_GET['product'];
$username = $_POST['Name']; #get name
$useraddress = $_POST['Email']; #get user email address
$subjectUser = $product . " PDF brochure from Specifile on-line";
$to = "specifile#gmail.com"; # recipient
$subject = "Confirmation: PDF Request - " . $product; #subject
$message = "The following person has requested the brochure - " . $product . "\n<br/>" . $username . " [ " . $useraddress . " ] "; #message
$attachment = $_SERVER['DOCUMENT_ROOT'] . "\\" . $pdf;
$attachment_type = "application/pdf";
$attachment_name = "brochure.pdf";
#open, read, then close the file
$fp = fopen( $attachment, 'rb');
$file = fread($fp, filesize($attachment));
fclose($fp);
#create boundary string
$num = md5(time());
$str = "==Multipart_Boundary_x{$num}x";
#encode data for safe transit
$file = chunk_split(base64_encode($file));
#define user header
$headers = "MIME-version: 1.0\r\n";
$headers .= "Content-type: multipart/mixed;\r\n";
$headers .= " boundary=\"{$str}\"\r\n";
$headers .= "From: Specifile on-line<specifile#infixion.co.za> \r\n";
#define confirmation header
$Confirmheaders = "MIME-version: 1.0\r\n";
$Confirmheaders .= "Content-type: text/html;";
$Confirmheaders .= " charset=\"UTF-8\"\r\n";
$Confirmheaders .= "From: Specifile on-line<specifile#infixion.co.za> \r\n";
#create message for user
$messageUser = "This is a multi-part message in MIME format\r\n";
$messageUser .= "--{$str}\r\n";
$messageUser .= "Content-type: text/html; charset=\"UTF-8\"\r\n";
$messageUser .= "Content-Transfer-Encoding: 8bit\r\n";
$messageUser .= "Hi " . $username . ", <p>The brochure you requested is attatched.</p> \r\n\n";
$messageUser .= "--{$str}\r\n";
#define non text attachment
$messageUser .= "Content-Type: {$attachment_type}; ";
$messageUser .= "name=\"{$attachment_name}\"\r\n";
$messageUser .= "Content-Disposition: attachment; ";
$messageUser .= "filename=\"{$attachment_name}\"\r\n";
$messageUser .= "Content-Transfer-Encoding: base64\r\n";
$messageUser .= "$file\r\n\n";
$messageUser .= "--{$str}";
mail($useraddress,$subjectUser,$messageUser,$headers);
mail($to,$subject,$message,$Confirmheaders);
?>
Not a real answer to your question, but have you considered using a ready-made mailing class like SwiftMailer? It does building the multipart message, and adding the attachments, for you.

Resources