www.mamboteam.com
Jx Development
Home arrow Support Forum
Saturday, 20 March 2010
 
 
Main Menu
Home
FAQs
Portfolio
File Archive
Bug Reports
Support Forum
Development Update
Work in Progress
Web Links
Contact Me
Component Demos
Jobline Demo
Mamblog Demo
Jambook Demo
Login Form





Lost Password?
No account yet? Register
Who's Online
We have 5199 guests online
Newsletter

Subscribe to our newsletter.






Donate
If you use and like my scripts, and would like further developments, please consider donating a few bucks.

External links
www.ledutveckling.com - The Yard - Utvecklaren - Rollspel.nu - Spelwebben - Gardener's Game Garage - My Pet Peeves - PSPnuts

Interesting Sites
Joomla!
Joomlahut
Netshine Joomla Tutorial
JX extensions on JED
Support Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Hack for attaching documents to submission (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Hack for attaching documents to submission
#4712
olle (Admin)
Admin
Posts: 1035
graph
User Online Now Click here to see the profile of this user
Re:Hack for attaching documents to submission 3 Years ago Karma: 17  
Good tip, this also works if a similar error occurs when using any other language file than English, since some strings might be missing in those.

It really should be a more clear error message, but since I'm planning on switching template system in the future I don't want to work so much on the current one.
 
Report to moderator   Logged Logged  
 
Olle Johansson
  The administrator has disabled public write access.
#4759
baldurmcqueen (User)
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
Re:Hack for attaching documents to submission 2 Years, 11 Months ago Karma: 0  
Hello

I had this thing working today, briefly, but stupidly forgot to take a spare copy of everything before I started making other changes.

Now, everything is back to the way it was before - that is, the attachment comes integrated into the e-mail; not as a picture/file, but as garbled text.

Anyone familiar with that problem?

Here is the code in jobline.php

Code:

function sendApplication( $id ) { global $database, $mosConfig_absolute_path, $mosConfig_live_site, $option, $cfgjl, $mainframe, $my, $Itemid; $row = new mosJobPosting( $database ); $row->load( $id ); if ( !$row->id ) { mosRedirect( "$mosConfig_live_site/index.php?option=$option&task=error&msg=" . _JL_NOSUCHJOB ); } else { $tmplvars = get_object_vars( $row ); foreach ( $_REQUEST as $k => $v ) { $tmplvars["req_$k"] = $v; } $reply_email = $tmplvars["req_email"]; $tmpl = new mxTemplate( "$mosConfig_absolute_path/components/com_jobline/templates/{$cfgjl['template']}" ); if ( $tmpl->setTemplate( "applicationemail" ) ) { // store the file information to variables for easier access $tmp_name= $_FILES['attach']['tmp_name']; $type = $_FILES['attach']['type']; $name = $_FILES['attach']['name']; $size = $_FILES['attach']['size']; $error = $_FILES['attach']['error']; $message = ''; $mime_boundary = ''; $tmpl->setVars( $tmplvars ); $tmpl->parseTemplate(); $message = $tmpl->getOutput(); // if the upload succeded, the file will exist if ( file_exists($tmp_name) ) { // generate a random string to be used as the boundary marker $mime_boundary = "<<<--==Multipart_Boundary_x".md5(mt_rand())."x"; // check to make sure that it is an uploaded file and not a system file if( is_uploaded_file($tmp_name) ) { $message .= "\n\n Attachment : $name"; // open the file for a binary read $file = fopen( $tmp_name,'rb' ); // read the file content into a variable $data = fread( $file,filesize($tmp_name) ); // close the file fclose( $file ); // now we encode it and split it into acceptable length lines $data = chunk_split( base64_encode($data) ); } // next, we'll build the message body // note that we insert two dashes in front of the // MIME boundary when we use it $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 if( $data ) { $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$name}\"\n" . "Content-Transfer-Encoding: base64 \n\n" . $data . "\n\n"; } $message .= "--{$mime_boundary}--\n"; } $Replyto = $reply_email; //function sendEmail( $email, $subject, $message, $fromname, $fromemail, $replyto, $mime_boundary ) sendEmail( $row->contactemail, _JL_APPLICATION_SUBJECT, $message, $cfgjl['mailfromname'], $Replyto, $Replyto, $mime_boundary); mosRedirect( "$mosConfig_live_site/index.php?option=$option&Itemid=$Itemid&task=thankyou&id=$id" ); } else { showError( _JL_ERRORSETTMPL . ": applicationemail" ); } } }
And here is the code in jobline.common.php
Code:

function sendEmail( $email, $subject, $message, $fromname='', $fromemail='', $replyto='', $mime_boundary='' ) { $headers = ""; if ( trim( $fromemail ) ) { $headers = "From: $fromname <$fromemail>\r\n"; } if ( trim( $replyto ) ) { $headers .= "Reply-To: <$replyto>\r\n"; } $headers .= "X-Priority: 3\r\n"; $headers .= "X-MSMail-Priority: Low\r\n"; $headers .= "X-Mailer: Joomla Open Source 1.12\r\n"; if( $mime_boundary ) { $headers .= "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; } @mail($email, $subject, $message, $headers); }
In the template, I have:
Code:

<form action="index2.php" method="POST" name="adminForm" enctype="multipart/form-data"> and where the input box is... <input type="file" name="attach" class="inputbox2" size="60" value="">
Any help would be greatly appreciated Thank you for an excellent component. Below is the attachment code as seen in a typical application - not attached, but integrated into the e-mail:
Code:

Attachment : ONLINE.BMP --<<<--==Multipart_Boundary_x77e5853ac728d175fe4cb854e452db9fx Content-Type: image/bmp; name="ONLINE.BMP" Content-Disposition: attachment; filename="ONLINE.BMP" Content-Transfer-Encoding: base64 Qk12AgAAAAAAAHYAAAAoAAAAIAAAACAAAAABAAQAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAMDAwACAgIAAAAD/AAD/AAAA//8A/wAAAP8A/wD//wAA ////AGZmZmZu7u7u7uZmZmZmZmZmZmZu5mqqqqpu7uZmZmZmZmZu5mqmZmZmqqZu5mZmZmZm5mqm ZgAAAAZqpm5mZmZmbmamZgD//39wBmpm5mZmZm5qZgD///f/fuAGpm5mZmbmpmD////3937u4Gpm 5mZm5qYHf///9/d+7u4GpuZmbmpgd3f///f3fu7u4GpmZm5qYKd3f//3937u53BqZmZmagqnd3f/ 9/d+7nf/BqZmZqYKqnd3f/f3fud/9wamZmpgqqqnd3f3935393dwpmZqYKqqqnd3AAB+/3e3cKZm amCqqqp3cGZmD3d3u3CmZmpgqqqqp3BmZgd+53dwpmZqYLuqqqpwZmZgfud2YGZmamC7u7qqoGZm YAYAYGBmZmpgu7u7u7sGZma7Zm7mZmZmpgu7u7u3cAAGu2puZmZmZqYLu7u7d3d3BmaqZmZmZmZm YLu7t3d3cGZ3ZmZmZmZmZmC7u7d3d3BmdmbuZmZmZmZmC7t3d3cGZmZm7mZmZmZmZmC3d3dwZmaq ZmZmZmZmZmZmAHd3BmZmqmd2ZmZmZmZmZmYAcGZmZmZmdmZmZmZmaZZpZpZplpaWaWmZZmZmZpZp aWaWaWaWlmlpZmZmZmaWaWlmmZlmlpZpaZZmZmZmlmlpZpZpZmaWaWlmZmZmZmmWaZlmaWaWmZZp mWZm --<<<--==Multipart_Boundary_x77e5853ac728d175fe4cb854e452db9fx--
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4760
olle (Admin)
Admin
Posts: 1035
graph
User Online Now Click here to see the profile of this user
Re:Hack for attaching documents to submission 2 Years, 11 Months ago Karma: 17  
The most common cause of this problem is malformed headers, the mail isn't properly formatted.

I can't tell you exactly what's wrong, but a quick look reveals that you are using different ways to mark new lines. You should try to replace all "\n" into "\r\n" unless they are already preceded by "\r".

A better way would be to use an API for formatting mails with attachments to make sure they are properly formatted. The Joomla API includes such a function, so it would probably be easier to just look it up in the Joomla developer documentation.
 
Report to moderator   Logged Logged  
 
Olle Johansson
  The administrator has disabled public write access.
#4761
baldurmcqueen (User)
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
Re:Hack for attaching documents to submission 2 Years, 11 Months ago Karma: 0  
Not only a fast reply, but the perfect one

You hit the nail on the head(er), everything working fine now.
I will look into the API as well, did not know about that possibility.

Thank you very much for the assistance Ollie.

Best wishes,
Baldur

Just for those who will follow, here is the code as it works for me.

1. The function sendApplication( $id ) in jobline.php:

Code:

function sendApplication( $id ) { global $database, $mosConfig_absolute_path, $mosConfig_live_site, $option, $cfgjl, $mainframe, $my, $Itemid; $row = new mosJobPosting( $database ); $row->load( $id ); if ( !$row->id ) { mosRedirect( "$mosConfig_live_site/index.php?option=$option&task=error&msg=" . _JL_NOSUCHJOB ); } else { $tmplvars = get_object_vars( $row ); foreach ( $_REQUEST as $k => $v ) { $tmplvars["req_$k"] = $v; } $reply_email = $tmplvars["req_email"]; $tmpl = new mxTemplate( "$mosConfig_absolute_path/components/com_jobline/templates/{$cfgjl['template']}" ); if ( $tmpl->setTemplate( "applicationemail" ) ) { // store the file information to variables for easier access $tmp_name= $_FILES['attach']['tmp_name']; $type = $_FILES['attach']['type']; $name = $_FILES['attach']['name']; $size = $_FILES['attach']['size']; $error = $_FILES['attach']['error']; $message = ''; $mime_boundary = ''; $tmpl->setVars( $tmplvars ); $tmpl->parseTemplate(); $message = $tmpl->getOutput(); // if the upload succeded, the file will exist if ( file_exists($tmp_name) ) { // generate a random string to be used as the boundary marker $mime_boundary = "<<<--==Multipart_Boundary_x".md5(mt_rand())."x"; // check to make sure that it is an uploaded file and not a system file if( is_uploaded_file($tmp_name) ) { $message .= "\r\n\r\n Attachment : $name"; // open the file for a binary read $file = fopen( $tmp_name,'rb' ); // read the file content into a variable $data = fread( $file,filesize($tmp_name) ); // close the file fclose( $file ); // now we encode it and split it into acceptable length lines $data = chunk_split( base64_encode($data) ); } // next, we'll build the message body // note that we insert two dashes in front of the // MIME boundary when we use it $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 if( $data ) { $message .= "--{$mime_boundary}\r\n" . "Content-Type: {$type};\r\n" . " name=\"{$name}\"\r\n" . "Content-Disposition: attachment;\r\n" . " filename=\"{$name}\"\r\n" . "Content-Transfer-Encoding: base64 \r\n\r\n" . $data . "\r\n\r\n"; } $message .= "--{$mime_boundary}--\r\n"; } $Replyto = $reply_email; //function sendEmail( $email, $subject, $message, $fromname, $fromemail, $replyto, $mime_boundary ) sendEmail( $row->contactemail, _JL_APPLICATION_SUBJECT, $message, $cfgjl['mailfromname'], $Replyto, $Replyto, $mime_boundary); mosRedirect( "$mosConfig_live_site/index.php?option=$option&Itemid=$Itemid&task=thankyou&id=$id" ); } else { showError( _JL_ERRORSETTMPL . ": applicationemail" ); } } }
2. The function sendEmail in jobline.common.php:
Code:

function sendEmail( $email, $subject, $message, $fromname='', $fromemail='', $replyto='', $mime_boundary='' ) { $headers = ""; if ( trim( $fromemail ) ) { $headers = "From: $fromname <$fromemail>\r\n"; } if ( trim( $replyto ) ) { $headers .= "Reply-To: <$replyto>\r\n"; } $headers .= "X-Priority: 3\r\n"; $headers .= "X-MSMail-Priority: Low\r\n"; $headers .= "X-Mailer: Joomla Open Source 1.12\r\n"; if( $mime_boundary ) { $headers .= "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; } @mail($email, $subject, $message, $headers); }
The applicationform.tmpl needs to have some simple changes as well, which can be seen in previous posts.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4762
baldurmcqueen (User)
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
Re:Hack for attaching documents to submission 2 Years, 11 Months ago Karma: 0  
OOppppsss.

That should have been, thank you very much for the assistance Olle
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4765
olle (Admin)
Admin
Posts: 1035
graph
User Online Now Click here to see the profile of this user
Re:Hack for attaching documents to submission 2 Years, 11 Months ago Karma: 17  
I'm glad it worked out. And don't worry about the name, a lot of people get it wrong so I'm used to it. =]
 
Report to moderator   Logged Logged  
 
Olle Johansson
  The administrator has disabled public write access.
#4829
maykel (User)
Fresh Boarder
Posts: 1
graphgraph
User Offline Click here to see the profile of this user
Re:Hack for attaching documents to submission 2 Years, 11 Months ago Karma: 0  
I tried to change my jobline component also with the texts that are put down in this forum. But I only get problems. Does it only work with the Englisch version? I want visitors to be able to put an attachment at the mail.

Is there someone who has a complet component which I can install in my joomla with this add on?

Thanks for helping me out.

Greetings from holland
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4834
olle (Admin)
Admin
Posts: 1035
graph
User Online Now Click here to see the profile of this user
Re:Hack for attaching documents to submission 2 Years, 11 Months ago Karma: 17  
Modifying scripts shouldn't be done if you don't know what you are doing, there are lots of things that can go wrong.

There will however be a CV attachment functionality for the application form in the next version of Jobline. If you can wait for the release.
 
Report to moderator   Logged Logged  
 
Olle Johansson
  The administrator has disabled public write access.
#4837
evert (User)
Junior Boarder
Posts: 30
graphgraph
User Offline Click here to see the profile of this user
Re:Hack for attaching documents to submission 2 Years, 11 Months ago Karma: 2  
Explaining in Dutch that it is possible and that it is working with me:

He maykel,
het is inderdaad mogelijk om je cv als attachment mee te sturen. Ik weet zo gauw niet meer welke aanpassingen daarvoor nodig zijn, omdat ik zo goed als het hele script aangepast heb naar mijn eigen wensen. Ik ben hier nog niet klaar mee, moet ook nog een check op komen dat alleen .doc , .txt, en .pdf bestanden verzonden kunnen worden.

Als je interesse hebt ( volgens mij wel) reply dan even op deze post en zet daar je mailadres bij zodat ik je de bestanden kan toezenden.

Succes, Evert
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4926
eric_zeus (User)
Fresh Boarder
Posts: 1
graphgraph
User Offline Click here to see the profile of this user
Re:Hack for attaching documents to submission 2 Years, 10 Months ago Karma: 0  
Hallo Evert,

Ik heb zeker belangstelling hiervoor. Het is namelijk precies waar ik op dit moment naar op zoek ben.

Gr. Eric<br><br>Post edited by: eric_zeus, at: 2007/04/26 20:24
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop
Advertisement
Polls
Is Joomla 1.0 support needed in future releases of our extensions?
 
Latest News
Most Read
Latest Commented
Bug Reporting (1 comments)
Mamblog - User blog component (61 comments)
The road to Jobline v1.2 (5 comments)
Export vBulletin users to Mambo (6 comments)
Jobline Documentation (4 comments)
Latest Posts

More...
 
Top! Top!