File attachments no longer included with email
-
Hello, like many others here, for several months, one of my forms sends emails but the attachments are no longer included even though the files do exist.
I thought an extension update would solve the problem, but it is still unresolved for me.
WP 6.6.1
CF7 5.9.8
Debian
Thank you
-
Same here. Spent hours trying to get an attached file to go through.
Where can we see the website in question?
See Setting up mail
What email settings do you have in the Mail tab panel?
To protect personal data, hiding email addresses in the settings or replacing them with dummy addresses is strongly advised. You can also include screenshots.
Thank you for your help !
[email* your-email placeholder “Email*”]
To : [your-email]
Reply-To: Christian [email protected], Kikou [email protected], tchoutche [email protected]
Cci: Christian [email protected], Kikou [email protected], tchoutche [email protected], zboub [email protected]uploads/adhesion/CGV-Solution-Nuisible.pdf
uploads/adhesion/Grille-tarifaire-Solution-Nuisible.pdfThere is no error (the plugin detects that the files do exist), and it worked fine before.
I had the same issue. With a lot of logging, I found out, that the attachments array in
wp-content/plugins/contact-form-7/includes/mail.php
have not the format as expected in
/wp-includes/pluggable.php
The indexes of the array were integers, instead of strings. The logging, I added looked like
$res = file_put_contents('/mypath/mail.log', date('Y-m-d H:i:s') . " [521] attachments: $attachments[0]\n", FILE_APPEND);
if ( ! empty( $attachments ) ) {
foreach ( $attachments as $filename => $attachment ) {
$filename = is_string( $filename ) ? $filename : '';
$res = file_put_contents('/mypath/mail.log', date('Y-m-d H:i:s') . " [526] $filename: $filename\n", FILE_APPEND);
try {
$phpmailer->addAttachment( $attachment, $filename );
$res = file_put_contents('/mypath/mail.log', date('Y-m-d H:i:s') . " phpmailer->addAttachment: $filename\n", FILE_APPEND);
} catch ( PHPMailer\PHPMailer\Exception $e ) {
$res = file_put_contents('/mypath/mail.log', date('Y-m-d H:i:s') . " phpmailer->addAttachment: $filename\n", FILE_APPEND);
continue;
}
}the result:
2024-07-31 15:39:10 [521] attachments: /mypath/wp-content/uploads/wpcf7_uploads/0043706875/pech.png
2024-07-31 15:39:10 [526] :I re-wrote the attachments function:
private function attachments( $template = null ) {
if ( ! $template ) {
$template = $this->get( 'attachments' );
}
$attachments = array();
if ( $submission = WPCF7_Submission::get_instance() ) {
$uploaded_files = $submission->uploaded_files();
foreach ( (array) $uploaded_files as $name => $paths ) {
if ( false !== strpos( $template, "[{$name}]" ) ) {
foreach ((array) $paths as $path) {
if ( file_exists( $path ) ) {
$attachments[basename($path)] = $path;
}
}
}
}
}
foreach ( explode( "\n", $template ) as $line ) {
$line = trim( $line );
if ( '' === $line or '[' == substr( $line, 0, 1 ) ) {
continue;
}
$full_path = path_join( WP_CONTENT_DIR, $line );
if ( file_exists( $full_path ) ) {
$attachments[basename($full_path)] = $full_path;
}
}
if ( $submission = WPCF7_Submission::get_instance() ) {
foreach ((array) $submission->extra_attachments( $this->name ) as $extra_attachment) {
if ( file_exists( $extra_attachment ) ) {
$attachments[basename($extra_attachment)] = $extra_attachment;
}
}
}
return $attachments;
}Then, the attachments were there (in pluggable.php):
2024-07-31 16:07:16 [525] filename type: string filename value: pech.png, attachment: /mypath/wp-content/uploads/wpcf7_uploads/0256448928/pech.png
2024-07-31 16:07:16 [527] pech.png: pech.png
2024-07-31 16:07:16 [531] phpmailer->addAttachment: /mypath/wp-content/uploads/wpcf7_uploads/0256448928/pech.pngAt the end, the phpmailer wouldn’t attach the files anyway, but that’s an issue of the php installation, I use.
I switched to smtp, which worked fine. I also could undo all my changes to the attachment function.
So, my recommendation is to use smtp or look at the attachments array which is processed in pluggable.php in line 521 to 531.
Best of luck, Stephan
Thank you, Stephan, for taking the time to respond. Unfortunately, it doesn’t work for me…
It’s very strange; the developer doesn’t take the time to understand what I mentioned: the form and file submission were working before, So I know how to attach an attachment (I even showed the links I provided, and the plugin locates them on the form editing page), so the wording is correct.. Several of us are having the issue, though…
@kzou13 what does not work for you?
Can’t you use smtp or can’t you add logging to the php files?
I’m pretty sure, the author receives a lot of emails ??
So, as long as the root cause is not identified, you need to find a work-around. Either re-write the function as I mentioned before or go back to an older version.
Cheers, Stephan
Stephen: I’m not sure if I am using SMTP –or how to determine that.
I use the plugin on 2 multisite networks. Same theme, same server, same version of the plugin, same version of WordPress. I will do a comparison of plugins in use. I know that they use different caching plugins. But, most plugins are the same.
If I figure it out, I’ll post the info here.
@nicollb You can use smtp only, if you installed and configured a smpt plugin, like
https://de.www.ads-software.com/plugins/smtp-mailer/
Stephan
-
This reply was modified 7 months, 3 weeks ago by
strzonnek.
Hello Stephan, I use WP Mail SMTP Lite, is it the problem ?! Thank you !
@kzou13 My crystal ball is currently in for repairs, so without more details, I’m afraid I can’t provide much help.
I couldn’t find SMTP Lite in the plugin search. I would expect some test option for an smtp plugin.
For me, I see a test button. I can click it.
Then, I can see some logs from the mail server and finally a success message.
I don’t know how to add an image here…
I have discovered that one of my sites sends attachments correctly. Email for this site is set up as a Google Workspace, separate from my hosting. The site that doesn’t send attachments is using the default setup for the hosting service. Tomorrow I will set that site up to use SMTP. I have the WP Mail SMTP — also the free/lite version. Will report back.
interesting thing is the site that works does use the plugin. The difference is what service handles mail itself -
This reply was modified 7 months, 3 weeks ago by
- The topic ‘File attachments no longer included with email’ is closed to new replies.