Forums

Putting enctype prevents email from being sent

highrockmedia 14 Jan, 2008
I have a file upload form and when I put enctype='multipart/form-data' in the general tab in Form tag attachment as suggested I then no longer get the notification email that a file has been uploaded. However, if I go into the upload directory, I see that the file has been uploaded successfully.

On the other hand if I take out that code, I then get the notification email but then the file no longer uploads.

This seems to be a bit of a catch 22. Any suggestions?
GreyHead 14 Jan, 2008
Hi brewster,

The two shouldn't be linked at all, the code that deals with each is pretty much completely separate.

Please take a Form Backup in the CF Form Manager and post it here or email it to me at the address in my sig and I'll take a look.

Bob
GreyHead 14 Jan, 2008
Hi brewster,

You need to have a value in the Minimum size field on the File uploads tab - please try 1 and see if that makes the difference.

Bob
highrockmedia 15 Jan, 2008
I just tried that and it didn't make a difference. I am thinking I should try creating a new form and see what happens.
GreyHead 15 Jan, 2008
Hi brewster,

It's working OK for me here. I've restored your file; put 1 in the min field; changed the email address to my own (you'll get the first couple though); temporarily removed the redirect URL; and turned debug on. Otherwise I'm using your code as is.

Bob

PS I notice that there are two 'name =' entries in the file input tag, probably isn't causing this problem but might give ChronoForms indigestion.
highrockmedia 15 Jan, 2008
I created a new form from scratch and with debug on, I get the message "Email not sent". I am wondering if there is an issue with our server and the enctype?
highrockmedia 15 Jan, 2008
Doing a Google search of enctype='multipart/form-data' and enctype='multipart/form-data' php indeed brings up several results of people having this same problem i am on a remote server. I noticed your ip was 192.168 etc.. so that could explain why yours works with my script. I have contacted Rackspace our colo host to see what they have to say about it.
GreyHead 15 Jan, 2008
Hi brewster,

My server Apache on another machine on the network here so it's semi-remote. We've seen plenty of examples where on-line form file upload works so I guess you've hit some configuration issue with Rackspace. Good luck with getting it resolved.

Bob
highrockmedia 15 Jan, 2008
rackspace answered back and said this:

"When you use enctype="multipart/form-data" you cannot access the form parameters. You have to construct a query string and append it to the action before submitting (a onclick event to the submit or button0."

Does that make any sense to you?
dniezby 22 Jan, 2008
Did you ever figure this out? I have the same problem with my forms.
highrockmedia 23 Jan, 2008

Did you ever figure this out? I have the same problem with my forms.


No I am going to have our PHP guy look at it today or tomorrow
GreyHead 23 Jan, 2008
Hi brewster,

I had a Google around this morning and found various things about setting the max_file_size in different places and ways and some about losing the $_POST entries but nothing that was very clear I'm afraid.

Bob
highrockmedia 23 Jan, 2008
Here are some similar problems: bugs.php.net
marc.info
usenet-forums
gidforums

All these people are having the same problem i am and one even says if worked fine on local server but not remote.

I searched Google for this: enctype= multipart/form-data php

Also -- Our Joomla is running on PHP 5.2.5

Edited to add url tags<br><br>Post edited by: GreyHead, at: 2008/01/23 18:03
GreyHead 23 Jan, 2008
Hi brewster,

Like you I found plenty of references to the problem and precious few clear explanations or fixes.

It seems to me that there are several different problems intertwined here:[list]
  • Sometimes there is a problem with the file size permitted for uploads, there are several ways of setting this and where and when it is done can make a difference
  • Sometimes switching encoding to 'multi=part/form-data' causes problems - the main symptom seems to be that the $_POST array is returned empty.
  • sometimes there is a problem with the form syntax or coding (or with supporting Javascript) that stops the form working correctly.
  • Sometimes the form works correctly but there are problems with saving the uploaded file (or emailing it).
  • [/list]What I'm learning is that it's really difficult to tease these apart without good debug access (and not necessarily simple even them).

    Bob
    highrockmedia 23 Jan, 2008
    Bob, thanks, I noticed that a user had this to say in another post here

    Yup, it's confirmed. A newly designed form and new table. After adding the enctype='multipart/form-data' to the General Tab, it no longer even gives me a name of the file, nor does it even send the eMail message.

    so I feel better it's not just me.

    Our PHP coder is working on this now, he knows Joomla really well also so I will post back when I learn something.

    Edited to add url tag<br><br>Post edited by: GreyHead, at: 2008/01/23 18:57
    GreyHead 23 Jan, 2008
    Hi brewster,

    This is dniezby, I was looking at his site last night and I don't think he has the same problem as you as it seems (to me at least) that the file and data are both received but the problem is with the email not being sent by Joomla. It may turn out that these are different symptoms of the same problem but I don't know yet.

    Bob
    dniezby 25 Jan, 2008
    Yup, it's me...Bob has been working with me trying to figure out this issue.

    OH MAN...I just remembered, I wrote a script for a form a little while ago that uploaded a file to the server and sent an eMail with a link to a recipient. I wonder if it will help to read through it?

    Let me see if I can find it.
    dniezby 25 Jan, 2008
    I found it.

    This script, was for an individual form submission where I knew the $_POST variables. But it should help...I hope.

    What it does is upload the file to s specified location and attach it to an email message.

    I can see that there would need to be a change in a way that the $_POST variables are collected...Perhaps an array? Though I suck at those.

    I remember, I wrote this for a flash form. Every variable that ends in var would be the field name="uploadedvar" in a regular form.

    
    <?php 
    $fileatt = "files/". $_POST["uploadfilevar"]; // Path to the file                 
    $fileatt_type = "application/octet-stream"; // File Type 
    $fileatt_name = $_POST["uploadfilevar"];
    $first = $_POST["firstvar"];
    $last = $_POST["lastvar"];
    $addy = $_POST["addyvar"];
    $city = $_POST["cityvar"];
    $state = $_POST["statevar"];
    $zip = $_POST["zipvar"]; 
    $dob = $_POST["dobvar"];
    $phone = $_POST["phonevar"];
    $wga = $_POST["wgavar"];
    $usc = $_POST["uscvar"];
    $subType = $_POST["subTypevar"];
    $stitle = $_POST["stitlevar"];
    $presynopsis = $_POST["synopsisvar"];
    	$synopsis = stripslashes($presynopsis);
    $from = $_POST["e_addyvar"];
    $email_from = $from; // Who the email is from 
    $email_subject = $_POST["subjectvar"];
    
    $email_txt = <<<EOF
    <html>
    <body bgcolor="#ffffff" text="#000000">
    <table align="center" bgcolor="#9999ff" border="1" cellpadding="2"
     cellspacing="2" width="100%">
      <tbody>
        <tr align="center">
          <td colspan="2" bgcolor="#9999ff" valign="top"><b>NEW SCREENPLAY
    SUBMISSION<br>
          </b><small>$date</small><b><br>
          </b> </td>
        </tr>
        <tr align="right">
          <td colspan="2" valign="top"><b><font color="#ff0000">$subType</font><br>
          </b></td>
        </tr>
        <tr>
          <td valign="top">Name<br>
          </td>
          <td valign="top">$last , $first   ($dob)<br>
          </td>
        </tr>
        <tr>
          <td valign="top">Address<br>
          </td>
          <td valign="top">$addy<br>
          </td>
        </tr>
        <tr>
          <td valign="top">City,State,Zip<br>
          </td>
          <td valign="top">$city, $state . $zip<br>
          </td>
        </tr>
        <tr>
          <td valign="top">Phone<br>
          </td>
          <td valign="top">$phone<br>
          </td>
        </tr>
        <tr>
          <td valign="top">eMail<br>
          </td>
          <td valign="top">$email_from<br>
          </td>
        </tr>
        <tr>
          <td valign="top">WGA Registration No<br>
          </td>
          <td valign="top">$wga<br>
          </td>
        </tr>
        <tr>
          <td valign="top">US Copyright No<br>
          </td>
          <td valign="top">$usc<br>
          </td>
        </tr>
        <tr>
          <td valign="top">Screenplay Title<br>
          </td>
          <td valign="top">$stitle<br>
          </td>
        </tr>
        <tr>
          <td colspan="2" valign="top">Synopsis<br>
          </td>
        </tr>
        <tr>
          <td colspan="2" valign="top">$synopsis<br>
          </td>
        </tr>
      </tbody>
    
    </table>
    </body>
    </html>
    EOF;
    
    // Check for Demo Submission.
    
    switch ($usc){
    case "demo":
    	$email_to = $from;
    	break;
    
    case "DEMO":
    	$email_to = $from;
    	break;
    
    case "Demo":
    	$email_to = $from;
    	break;
    
    default:
      $email_to = "dniezby@sample.com";
    	}
    
    
    $headers = "From: ".$email_from; 
    
    $file = fopen($fileatt,'rb'); 
    $data = fread($file,filesize($fileatt)); 
    fclose($file); 
    
    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
       
    $headers .= "\nMIME-Version: 1.0\n" . 
                "Content-Type: multipart/mixed;\n" . 
                " boundary=\"{$mime_boundary}\"";  
    $email_message .= $email_txt . "\n\n" . 
                    "--{$mime_boundary}\n" . 
                    "Content-Type:text/html; charset=\"iso-8859-1\"\n" . 
                   "Content-Transfer-Encoding: 7bit\n\n" . 
    $email_txt . "\n\n";  
    
    $data = chunk_split(base64_encode($data)); 
    
    $email_message .= "--{$mime_boundary}\n" . 
                      "Content-Type: {$fileatt_type};\n" . 
                      " name=\"{$fileatt_name}\"\n" . 
                      "Content-Disposition: attachment;\n" . 
                      " filename=\"{$fileatt_name}\"\n" . 
                      "Content-Transfer-Encoding: base64\n\n" . 
                     $data . "\n\n" . 
                      "--{$mime_boundary}--\n"; 
    
    $ok = @mail($email_to, $email_subject, $email_message, $headers); 
    
    unlink ($fileatt);
    
    ?> 
    <br><br>Post edited by: dniezby, at: 2008/01/24 20:47
    dniezby 28 Jan, 2008
    Have you taken a look at this code yet?

    Which file processes the forms so I can take a look as well and see if I can't figure out why it's not sending the form.
    dniezby 28 Jan, 2008
    I think I found the problem.

    Check line 91 of chronocontact.html.php

    There is no parsing of enctype.

    This would explain everything. If you add the enctype, it would cause an error because it's got file attached without enctype and it's not in the form setup. If you don't add the enctype, it would send the mail on php's default settings. No file = nothing but text. Ok to send.

    I would edit the code myself and test it but I don't know what variable you're using for enctype nor do I know if it should query the database as you have some entries that do and some that don't.

    Here is the line as you have it now. Notice the absence of enctype?

    <form 
    name="<?php echo "ChronoContact_".$rows[0]->name; ?>" 
    id="<?php echo "ChronoContact_".$rows[0]->name; ?>" 
    method="<?php echo $paramsvalues->formmethod; ?>" 
    action="<?php echo $actionurl; ?>" 
    <?php echo $rows[0]->attformtag; ?>>


    Edited to break up long line<br><br>Post edited by: GreyHead, at: 2008/01/28 16:13
    highrockmedia 28 Jan, 2008

    I think I found the problem.

    Check line 91 of chronocontact.html.php

    There is no parsing of enctype.

    This would explain everything.



    That makes sense, I had our PHP guy write his own function for upload and it works fine so we are using chronoforms to execute our own upload / email notify code but not using chronoforms upload function and it works fine.

    I am guessing because there are different versions of chronoforms out there (depending on when you downloaded / updated it in Joomla), thats why it works for some people and not for others.<br><br>Post edited by: brewster, at: 2008/01/28 16:07
    GreyHead 28 Jan, 2008
    Hi brewser,

    I don't think that is the problem, the enctype attribute is added in the $rows[0]->attformtag part of the line.

    If it's OK with you and your IT Guy I would be interested in seeing the function he created to see if we can use it to create a workaround for this problem. It's proving tricky yo diagnose because I can't replicate it on my test sites (or the live ones come to that).

    Bob
    highrockmedia 28 Jan, 2008

    If it's OK with you and your IT Guy I would be interested in seeing the function he created to see if we can use it to create a workaround for this problem. It's proving tricky yo diagnose because I can't replicate it on my test sites (or the live ones come to that).

    Bob


    Sure I will send you an email with instructions how to login to demo and see the code. It's a work in progress but it is working.
    GreyHead 28 Jan, 2008
    Hi brewster,

    Thanks for this, all received. I'll take a look, probably tomorrow morning.

    Bob
    dniezby 28 Jan, 2008
    I hope it works. I've been delaying this form I need to get up on our site for sometime. I'd love to use chronoforms because of it's styling capabilities and database use ONLY if needed. But if I don't have a solution soon I'll have to use another form component. But it makes some pretty ugly forms and doesn't allow styling as well as chrono
    Max_admin 01 Feb, 2008
    Hi,

    Please look at the solution suggested here.

    Cheers,

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    AgentM 01 Apr, 2009
    Did anybody find a solution for this problems? Seems like I'm having the exact same thing: When I add enctype='multipart/form-data', I get the upload but no mail, when I delete it I get a mail but no upload. I already added $mosConfig_fileperms = '0644' in the configuration.php. And unfortunately I don't have a PHP guy who can write me an own function😟 It's really frustrating.
    (I'm working with Chronoforms 2.5 on Joomla 1.5)
    Max_admin 01 Apr, 2009
    Hi AgentM,

    Please turn the DEBUG ON and if it tells "Emails sent" then the email is getting blocked by some thing!

    Regards
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    AgentM 01 Apr, 2009
    Hi Max,

    thanx for the answer.
    Debug is on. Has to be something else - but what? :?
    Max_admin 01 Apr, 2009
    what does the debug say ?
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    AgentM 02 Apr, 2009
    I'm assuming it would say something after I submit the form, right? But it says nothing... It straight goes to the redircet URL I entered as if everything was alright.
    Max_admin 02 Apr, 2009
    Hi, for teh debug to work you need to remove any redirect URL, please remove it then try it to see the DEBUG which will tell you if the email was sent or not!

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    QueenTut 16 Jul, 2009
    Is there a happy ending to this thread? I have a similar problem. When I enable uploads the emails stop. Debug tells me the email was sent successfully. To test it I am using an email address from the site to send it to my email address which is on a different site. It works when upload is not enabled or when upload is left enabled but I take the upload field off the form.
    The uploaded file is very small (bmp|gif|jpg|png|wmf{200-1}) and I did not included the upload on the email template.
    When uploads are enabled and after I submit the form, the incoming mail on my mail(mac) times out and I get an error message or I get nothing.
    Same problem when I put enctype="multipart/form-data" in the form tag attachment under the general tab.

    How do I enable the uploads but still allow the notification email to come through?

    PS Please include every step, I know very little php.

    Thanks in advance.
    Max_admin 17 Jul, 2009
    Hi QueenTut,

    when you have uploads enabled but you don't choose a file to upload before submitting the form, do you get the email ?

    Regards
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    QueenTut 17 Jul, 2009
    Thank-you for asking.
    The short answer - even empty, the upload field stops the email.

    I had the form working without the upload field.
    Using the Wizard Edit, I put the File Upload label&field back on the form. Filled in the required fields and left the File Upload field blank. Submitted the form with debug on.
    The confirmation page had the following debug message:
    1. Form passed first SPAM check OK
    2. Form passed the submissions limit (if enabled) OK
    3. Form passed the Image verification (if enabled) OK
    4. Form passed the server side validation (if enabled) OK
    5. $_POST Array: ...(looked fine)
    6. $_FILES Array: Array ( [signature] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )
    7. Form passed the plugins step (if enabled) OK

    Noted the [error] in 6. In the file uploads tab I changed the sizes from {200-1} to {200-0} and tried again but I got the same debug message.

    Clicked submit on the confirmation page. The thank-you page came up with the following debug message

    1. An email has been SENT successfully ...
    2. Debug End

    But alas no email.
    GreyHead 17 Jul, 2009
    Hi Queentut,

    Seems to me that you have some linked errors here.

    The file upload and the email aren't linked in ChronoForms so what I think is happening is that there is probably a PHP error that crashes the PHP execution at the file upload stage so it never gets as far as sending the email.

    The [error] => 4 in the $_FILES array is a Server error, not a ChronoForms error - I think it means 'No File Uploaded' - that would seem to be true. To fix this you probably do need to add enctype="multipart/form-data" on the General Tab.

    There's still an error after this and my guess it that there may be some mismatch between the field_names, or a permissions problem with the uploads folder.
    [sendfb][/sendfb]
    Bob
    QueenTut 17 Jul, 2009
    Hi Bob,
    I added enctype="multipart/form-data" as suggested but it didn't change the outcome.

    Trying to locate the source of the problem, this morning with the form wizard, I made a simple form with 3 text boxes, the file upload, a captcha and a submit button.
    Saved it.
    Made a very simple confirmation page and a thank-you page that used only two fields and very basic html.
    On the first try, the image uploaded and the email was received with the image showing on the email. Wonderful! but it only happened once. When I repeated the test, the image uploaded and the email was sent but I only got the name of the image in the email. Better than nothing. The image is only an 8kb gif.

    Added text boxes to the form but kept the email template simple. The email kept getting through and the file continued to upload.

    So then I deleted the simple email message I had made at the beginning and kept the email template blank. It defaulted to include all the fields on the form and the email stopped working at 7 fields on the email. The email I received with 7 fields is 2.2kb so size isn't the problem.

    Every try, successful or not, got the same debug message:
    6. $_FILES Array: Array ( [signature] => Array ( [name] => flag.gif [type] => image/gif [tmp_name] => /tmp/phplNQPWg [error] => 0 [size] => 6120 ) )

    The database tables for any of these forms seem to be fine.

    Should I accept the inevitable and keep the emails tiny or is there a simple fix?

    Attached is a copy of the form backup.

    Thanks for taking a look at this. You guys must be at this 24/7!
    GreyHead 17 Jul, 2009
    Hi queentut,

    The bad news is that it's working perfectly here. I've turned off the Anti-Spam for testing and changed the upload path but otherwise the form is unchanged.

    I suspect that the upload folder on your server may not be writeable by the Joomla user. Please try setting Error Reportign to Maximum in the Site Global Configuration and see if you they get any helpful error messages.

    Bob
    QueenTut 18 Jul, 2009
    Hi Bob,

    Thanks for trying it on your system.

    I set error reporting to max. I didn't recognize any errors or warnings when I turned the Debug System on.

    Just to clarify - Uploading is fine. The files upload nicely to the default folder or any folder I specify in the Full File Uploads Path under the Uploads Tab. It is the email/upload combo that seems to limit the size or complexity of the email I can send.

    I haven't checked out the solution at http://www.chronoengine.com/index.php?option=com_fireboard&Itemid=37&func=view&catid=5&id=5260#5260 Max suggested to dniezby in February/08 because at first glance that seems to deal with an uploads problem.

    For now I'm okay with little notification emails and maybe that's okay for others browsing this forum for a solution to the same problem.

    I'll get back to trying other things when I need to include the uploaded images in the email or send an email with more than 7 fields. Maybe by then I or someone else will have figured it all out.

    Cheers for now.
    Queen Tut
    needshelp 28 Oct, 2011
    Amen, the solution worked for me!!! :mrgreen:
    This topic is locked and no more replies can be posted.