Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 52
  1. #21
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    Something else here. You're trying to upload files into your images directory... while not a requirement, why not the uploads directory (DIR_FS_UPLOADS)?

    Are you sure that permissions are set and possible to place either these or similar files to the current destination location? (DrByte advised to be sure that the directory was readable, which makes me wonder if there is something in the process that fails if the permissions of the htaccess either in that directory or the first one above it doesn't like the file type that is being uploaded. For the sake of testing, may I suggest attempting to upload image type files until that is successful, then try your *.docx or similar style files and see how it goes... so anything that ends with a lowercase extension of say, .jpg, .gif, .jpeg, etc...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  2. #22

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    Quote Originally Posted by mc12345678 View Post
    Something else here. You're trying to upload files into your images directory... while not a requirement, why not the uploads directory (DIR_FS_UPLOADS)?

    Are you sure that permissions are set and possible to place either these or similar files to the current destination location? (DrByte advised to be sure that the directory was readable, which makes me wonder if there is something in the process that fails if the permissions of the htaccess either in that directory or the first one above it doesn't like the file type that is being uploaded. For the sake of testing, may I suggest attempting to upload image type files until that is successful, then try your *.docx or similar style files and see how it goes... so anything that ends with a lowercase extension of say, .jpg, .gif, .jpeg, etc...
    I was using the images directory as a product of working from the foundation of manufacturers.php. I figured that if that was a directory already setup to accept uploads then it would be a good place to test in, hopefully also applying to my created sub-directory.

    I can try uploads (or just DIR_FS_CATALOG?), should I still try testing the upload with image filetypes if I move away from the images directory?

    I'm not sure about the permissions of the destination.

    This is what I tried using the ->parse() & ->save() conditions. I still get the same error (testing upload of a .txt file - I'll let you know what the result is with a .jpg), maybe there's something up with the declaration of the new upload class and it doesn't even get as far as these if statements?

    Code:
    $error = false;
    if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
    	//Setting the input fields to php variables
      $name = zen_db_prepare_input($_POST['name']);
      $email_address = zen_db_prepare_input($_POST['email']);
      $phone = zen_db_prepare_input($_POST['phone']);
      $zip = zen_db_prepare_input($_POST['zip']);
      $apply_attachment = new upload('attach');
      $apply_attachment->set_destination(DIR_FS_CATALOG . DIR_WS_IMAGES . "career_uploads/");
      $attachments_list = array();
      $error_msg = '';
    
      //checking if the value of the email field is valid with zencart func
      $zc_validate_email = zen_validate_email($email_address);
    	
      //handle file upload/attachment
      if ( $apply_attachment->parse() && $apply_attachment->save() ) {
    	  if ($apply_attachment->filename != 'none') {
    		$attachments_list[] = $apply_attachment->file;
    	  } else {
    		$error_msg = "Filename is empty or invalid.";
    		$error = true;
    	  }
      } else {
    	  $error = true;
    	  $error_msg = "You must successfully attach a file";
    	  return false;
      }
    Last edited by RobertH; 14 Mar 2017 at 07:27 PM. Reason: .txt file

  3. #23

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    Trying a .jpg yielded the same result. Do I need to use "$apply_attachment = new upload($_POST['attach']);"?

    The problem is somewhere in the use of the upload class and/or use of $apply_attachment. If I remove the "new upload()", "set_destination", and the "$apply_attachment->parse() && ..." nesting if statements then the form goes back to successfully submitting. If any of those are present though it stops working. This is even true for the if statements which doesn't make sense to me because shouldn't it just return a false if there's a problem with the condition and resolve to the else?

    If I leave only the if statements and change "$apply_attachment->parse() && $apply_attachment->save()" to something simple like "1 == 0" then I don't get a 500 http error (the form doesn't submit, as the else there has return false;, but I dont get an error page). So just entering the if statement with "$apply_attachment->parse() && $apply_attachment->save()" is throwing the error (as it should, since with only the if statements in there's no 'new upload()' or anything - but if those exist then i get an error as well).

  4. #24
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    To confirm that the upload process works on the store side, try the following:

    Create a product in the store, include a minimum of 1 quantity (more as necessary).
    Create an option name that relates to an upload/file.
    Add the attribute to the product.
    Goto the product, add/upload a file, add the product to the cart.

    Regarding the upload usage within the code. Either what is the generated source code for the attach input or what code are you using to generate the field?

    As much as it might "make sense" to use the $_POST data, the fact that the field is intended to be a file import field means that other things happen on submission where all that is needed is the name of the field for the remainder of the upload code to work. That name should match at creation as well at declaration of the upload class.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #25

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    Quote Originally Posted by mc12345678 View Post
    To confirm that the upload process works on the store side, try the following:

    Create a product in the store, include a minimum of 1 quantity (more as necessary).
    Create an option name that relates to an upload/file.
    Add the attribute to the product.
    Goto the product, add/upload a file, add the product to the cart.

    Regarding the upload usage within the code. Either what is the generated source code for the attach input or what code are you using to generate the field?

    As much as it might "make sense" to use the $_POST data, the fact that the field is intended to be a file import field means that other things happen on submission where all that is needed is the name of the field for the remainder of the upload code to work. That name should match at creation as well at declaration of the upload class.
    I followed those steps and was able to add the test product to the cart after uploading the file. It said "File saved successfully" and I found the file in httpdocs/images/uploads/ (albeit it being renamed to "1.jpg").

    As far as the file input field this is all I'm using to generate the field.

    Code:
    <input type="file" name="attach" />

  6. #26

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    UPDATE:

    So after the success in uploading the file with the product attribute, I was looking at classes/shopping_cart.php and where it uses the upload class. I saw that it has "include(DIR_WS_CLASSES . 'upload.php');" so I put that into my code as well and I don't get a 500 error page now, the form successfully submits.

    The attached file is not uploaded, and there's no attachment on the resulting email, but it redirects to an "?action=success" page and the email still sends with the rest of the form data. This is my code now:

    Code:
    <?php
    /**
     * Careers Application test page
     */
    
    require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
    include(DIR_WS_CLASSES . 'upload.php');
    
    $error = false;
    if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
      //Setting the input fields to php variables
      $name = zen_db_prepare_input($_POST['name']);
      $email_address = zen_db_prepare_input($_POST['email']);
      $phone = zen_db_prepare_input($_POST['phone']);
      $zip = zen_db_prepare_input($_POST['zip']);
      $apply_attachment = new upload('attach');
      $apply_attachment->set_destination(DIR_FS_UPLOADS);
      $attachments_list = array();
      $error_msg = '';
    
      //checking if the value of the email field is valid with zencart func
      $zc_validate_email = zen_validate_email($email_address);
    	
      //handle file upload/attachment
      if ( $apply_attachment->parse() && $apply_attachment->save() ) {
    	  if ($apply_attachment->filename != 'none') {
    		$attachments_list[] = $apply_attachment->file;
    	  } else {
    		$error_msg = "Filename is empty or invalid.";
    		$error = true;
    	  }
      } else {
    	  $error = true;
    	  $error_msg = "You must successfully attach a file";
    	  return false;
      }
      
      
    
    	
      
    
      if ($zc_validate_email and !empty($name) and !empty($phone)) {
        
    	$send_to_email = "[address redacted]";
        $send_to_name =  "Robert Test";
        
        // Prepare Text-only portion of message
        $text_message = OFFICE_FROM . "\t" . $name . "\n" .
        OFFICE_EMAIL . "\t" . $email_address . "\n\n" .
        '------------------------------------------------------' . "\n\n" .
        $name .  "\n\n" . $email_address .  "\n\n" . $phone .  "\n\n" . $zip . "\n\n" .
        '------------------------------------------------------' . "\n\n" .
    	
        // Prepare HTML-portion of message
        $html_msg['EMAIL_MESSAGE_HTML'] = "Application submitted by: " . $name . "<br/><br/>"
    		. "Applicant Information:<br/><br/>"
    		. "Name: " . $name . "<br/>"
    		. "Email: " . $email_address . "<br/>"
    		. "Phone: " . $phone . "<br/>"
    		. "ZIP: " . $zip . "<br/><br/>";
        $html_msg['CONTACT_US_OFFICE_FROM'] = OFFICE_FROM . ' ' . $name . '<br />' . OFFICE_EMAIL . '(' . $email_address . ')';
        //$html_msg['EXTRA_INFO'] = $extra_info['HTML'];
        // Send message
        zen_mail($send_to_name, $send_to_email, 'Career Application Submitted', $text_message, $name, $email_address, $html_msg, 'default');
    
        zen_redirect(zen_href_link(FILENAME_APPLY_TEST, 'action=success'));
      } else {
        $error = true;
        if (empty($name)) {
          $messageStack->add('contact', ENTRY_EMAIL_NAME_CHECK_ERROR);
        }
        if ($zc_validate_email == false) {
          $messageStack->add('contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
        }
        if (empty($phone)) {
          $messageStack->add('contact', ENTRY_EMAIL_CONTENT_CHECK_ERROR);
        }
      }
    } // end action==send
    
    
    // include template specific file name defines
    $define_page = zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/html_includes/', FILENAME_DEFINE_APPLY_TEST, 'false');
    
    $breadcrumb->add(NAVBAR_TITLE);
    
    ?>
    So it still looks pretty far from working since nothing about the file upload seems to be sticking, but it's not an error so maybe a step forward?

  7. #27
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    Okay, so that negates the need for part of the below:
    So, how about this for a test, try changing the storage path to DIR_FS_UPLOADS as a test to validate storage location within/by your code.

    But this may still apply: Then, since not setting the extension(s) that are permitted, would again recommend a "generic" extension such as the jpg file that was uploaded.

    By not setting the acceptable extension(s) the upload is limited to a specific set identified in the upload class.

    As to the need to load the class, that's actually in a way unusual, because the admin side manufacturers.php doesn't specifically load it. I was considering that to be the next if the above uploads directory also caused a 500...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #28
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    Oh yeah, might also remove the return false line... not sure where it is trying to return to... :)
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #29
    Join Date
    Jul 2012
    Posts
    16,718
    Plugin Contributions
    17

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    Ugh. And reason for no attachment is because the attachment_list isn't sent to zen_mail...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #30

    Default Re: Using zen_mail function with a user-filled form, including file attachment.

    Quote Originally Posted by mc12345678 View Post
    Okay, so that negates the need for part of the below:
    So, how about this for a test, try changing the storage path to DIR_FS_UPLOADS as a test to validate storage location within/by your code.

    But this may still apply: Then, since not setting the extension(s) that are permitted, would again recommend a "generic" extension such as the jpg file that was uploaded.

    By not setting the acceptable extension(s) the upload is limited to a specific set identified in the upload class.

    As to the need to load the class, that's actually in a way unusual, because the admin side manufacturers.php doesn't specifically load it. I was considering that to be the next if the above uploads directory also caused a 500...
    Yea I've changed the set_destination to DIR_FS_UPLOADS and am using the .jpg file. I agree that it's unusual to "have to" include the class specifically, but it seems to have at least done something.

    Quote Originally Posted by mc12345678
    Oh yeah, might also remove the return false line... not sure where it is trying to return to... :)
    Okay I can take it out, the return false was supposed to stop the form submission in that else case. The page containing the form re-loads mostly barren since there's no php to populate it. This is fine right now as it just lets me know that the form wasn't successful.

    Quote Originally Posted by mc12345678
    Ugh. And reason for no attachment is because the attachment_list isn't sent to zen_mail...
    Oh yea I know that the attachment won't be there, but the file isn't uploaded via the form either and for there to be anything to even pass to $attachments_list[] I need to get the file uploaded successfully first.

 

 
Page 3 of 6 FirstFirst 12345 ... LastLast

Similar Threads

  1. v155 My Account screen does not come-up with form filled-in
    By wonged in forum Upgrading to 1.5.x
    Replies: 3
    Last Post: 31 Jul 2016, 01:49 PM
  2. v139h Attribute file not being sent as an attachment with order
    By RescoCCC in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 1 May 2015, 07:20 PM
  3. Replies: 6
    Last Post: 25 Oct 2013, 10:43 PM
  4. How do I send an attachment with zen_mail()? v1.3.8
    By jenbullfrog in forum General Questions
    Replies: 18
    Last Post: 16 Jun 2011, 10:14 AM
  5. Code Needed For File Attachment Upload with PHP Form
    By bumba000 in forum General Questions
    Replies: 0
    Last Post: 28 Mar 2007, 07:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR