• Resolved hbedit

    (@hbedit)


    Hello all,

    I have a WP website running well since years, and since a few days/weeks, attachments are not sent anymore when someone uses the Contact form 7 plugin.

    My website used to have “wpcf7_uploads” in a custom “images” folder (instead of “wp-content/uploads” path) and Contact form attachments were working pretty well since the issue appeared.

    Folder authorization is set on “777” (folder can be read, written, and executed).

    I have tried to add on “wp-config.php” the suggested line, without result :
    define( ‘WPCF7_UPLOADS_TMP_DIR’, ‘/www/images/wpcf7_uploads’ );

    I have also tried to delete this wpcf7_uploads folder and create another one in “wp-content/uploads“, but it didn’t work either.

    I am running out of solutions, do you have any idea to fix this issue ?

    Many thanks to anyone who could bring me a solution ??

Viewing 15 replies - 1 through 15 (of 15 total)
  • I have encountered the same problem since updating to version 5.4.1, I no longer receive files attached to emails, although I had no problems before.
    Is there a way to fix this problem?

    Thank you

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    Where can we see the website in question?

    I’m having the same issue. Looking at the emails, it started ~14 days ago. I think it was after the 5.4.1 update.

    After trying different things – from checking permissions, to using a custom folder and disabling all other plugins – I enabled WordPress’s debug[0] mode and managed to catch the error:

    [13-May-2021 18:59:58 UTC] PHP Notice: Failed to attach a file. /srv/users/[...]/public/files/android/p/f/wpcf7_uploads/1844730695/test.png is not in the allowed directory. in /srv/users/[...]/public/files/android/p/wp-content/plugins/contact-form-7/includes/mail.php on line 147

    I couldn’t see any problems on the browser side and nothing changed on my server (other than the usual Ubuntu security updates, as far as I know).

    My temporary fix was to replace 5.4.1 with 5.4, which works well: https://github.com/takayukister/contact-form-7/releases/tag/v5.4

    Since 5.4 works without problems, I assume it’s something that changed on 5.4.1 @takayukister

    —-
    [0]:

    define( 'WP_DEBUG', true);
    define( 'WP_DEBUG_LOG', true);
    Thread Starter hbedit

    (@hbedit)

    Mmmh, sounds like a good idea to downgrade to 5.4 indeed.

    That’s what i have done and it worked PERFECTLY, thank you so much Celso !

    TO TAKAYUKI: first thank you for your awesome plugin !

    It seems that your last update (5.4.1) makes the form attachments crash. For information i am using AVADA WordPress theme.

    Cheers.

    Hi Erik,

    Ye been there, followed the steps, but still no luck. The folder that holds the temp file is created, when i submit the form with a file attached, the time stamp on that folder is updated, but the file doesnt appear in my inbox with the email.

    I checked to make sure the file has the right permissions, and all good.

    • This reply was modified 3 years, 5 months ago by accend4web.

    hello @accend4web, I have seen that some users have problems with this but I when I try this function simply works, this is the reason why I suspect is some kind of server / wordpress / cf7 misconfiguration!

    are you sure you set correctly the forder owner? (chown …)
    what outputs ls -l of that folder? (ls -l /var/www/mywebsite….)

    Hi all,

    File attachment only works for me on v 5.3.2 as highest version.

    Just did some updates.

    Got the same “Failed to attach a file… is not in the allowed directory” error as Celso Azevedo with v5.4.1

    Downgrading to v5.4 does fix it.

    We’ve run into the similar issue on our site, since a recent update the attachments are no longer being sent. I’ve been able to identify the problem and including the solution below.

    Problem
    Our site is hosted on Pantheon. So the WordPress code lives in /code folder and all files live in /files folder. This was not the problem before.

    Per documented instructions the upload path can be customized to any location. In case of server such as Pantheon the standard path of files /wp-content/uploads is just an alias to the /files folder.

    The code in the Contact Form 7 plugin in file mail.php does the explicit check that the attachment is in the WP_CONTENT directory if ( ! wpcf7_is_file_path_in_content_dir( $path ) ) {. In our case this will always be false so the attachment is never attached although it does exist in a directory that the plugin can freely read.

    This is a wrong assumption for the code to make. It may work with traditional servers. But as hosts try to optimize content delivery by segmenting out files, this will fail. Pantheon is being one such host.

    Replication Steps
    * Create a WordPress installation
    * Create a file storage folder outside of the WordPress code folder
    * Create a symbolic link from /wp-content/uploads to lead to a new folder created in a previous step
    * Configure a form with file attachment
    * Submit the form, see the email with out an attachment

    Proposed Solution
    Replace the statement if ( ! wpcf7_is_file_path_in_content_dir( $path ) ) { with a check that the plugin user has access to the directory and permissions to read the attached file. This will ensure that only authorized files are attached and will not fail when the files live outside of the WordPress structure.

    If that doesn’t seem to be the best solution, then another option is to verify that the file lives in the directory specified by WPCF7_UPLOADS_TMP_DIR which may be an absolute server path and also live outside of WordPress root directory.

    @takayukister Please let me know if this is sufficient information to create a solution. Don’t hesitate to reach out if you need any additional

    • This reply was modified 3 years, 5 months ago by makbeta.
    • This reply was modified 3 years, 5 months ago by makbeta.

    Wow, good job figuring that out!

    I can confirm the upload path on my website is also not in the standard wp-content folder. So makbeta is very likely correct.

    Interesting. I’m also using a custom directory for uploads.

    The temporary workaround until this issue is addressed, for those who host their files in a different location is to comment out the following code in /contact-form-7/includes/mail.php. This solved the issue with attachment for me.

    if ( ! wpcf7_is_file_path_in_content_dir( $path ) ) {
      if ( WP_DEBUG ) {
        trigger_error(
          sprintf(
            /* translators: %s: Attachment file path. */
            __( 'Failed to attach a file. %s is not in the allowed directory.', 'contact-form-7' ),
            $path
          ),
          E_USER_NOTICE
        );
      }
    
      return false;
    }
    • This reply was modified 3 years, 5 months ago by makbeta. Reason: improved call formatting

    No success with the new update (5.4.2). This made me try a few things again and finally managed to fix it.

    It works if I define the temporary folder in the wp-config.php file. I have to use the full path to the default temporary folder. In my case it’s something like this:

    define( 'WPCF7_UPLOADS_TMP_DIR', '/srv/users/celso/apps/celso/public/extras/blog/wp-content/uploads/wpcf7_uploads/' );

    To give you some context, this WordPress installation is inside a subfolder (/extras/blog/) and uses a custom uploads folder (/extras/blog/p/).

    The full path part is important. It doesn’t work with just /wp-content/uploads/wpcf7_uploads/ or /extras/blog/wp-content/uploads/wpcf7_uploads/. It also doesn’t work if I use anything else than the default folder.

    If you’re able to edit your wp-config.php file, try this. It seems to be a more permanent solution than using an outdated version or having to modify the plugin code every time there’s an update.

    Just keep in mind that you may have to update the path every time something changes (eg: if you move to a different hosting provider).

    • This reply was modified 3 years, 4 months ago by Celso Azevedo.
    Thread Starter hbedit

    (@hbedit)

    Hello guys, thank you so much for all your suggestions.

    From my side, i have tried Celso’s solution (inserting the whole path in wp-config.php file) and it worked like a charm! :-))

    I hope it will help other members.

    Cheers.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Attached files are not sent anymore’ is closed to new replies.