Skip Navigation

[Resolved] Can form notifications include attachments?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by hernanL 5 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2699734

I can't find an option in this regard. It's possible? If built-in is not possible, what hook would you recommend to achieve this?

What happens is that in a project built with Toolset I am going to work with an image gallery. I would be happy to have all the files in one place for bulk download (if you have seen someone in a similar dilemma and there is a simpler option, I would appreciate it)

Thanks greetings

#2699787

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset Form do not support attachment for email notification.

You may try to use the Toolset Form's hook "cred_submit_complete":
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete
OR
hook "cred_save_data"
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

And use WordPress built-in email function wp_mail() and setup the attachment:
- https://developer.wordpress.org/reference/hooks/wp_mail/

#2699901

Thank you very much, I have made progress. I have managed to send myself an email with links to the images (which would be an improvement for me anyway, at least I could select all the links and download them with a program or browser extension)

But I'm a bit stuck with finally attaching the images to the mail. I check the wordpress documentation and it should work, but it doesn't. Could you give me a hand? Am I missing something in the example code?

Thanks greetings

-------
add_action('cred_submit_complete', 'enviar_datos_por_email_con_imagenes', 10, 2);

function enviar_datos_por_email_con_imagenes($post_id, $form_data) {
if ($form_data['id'] == '12869') {

$contenido = "Se han enviado datos e imágenes.\n";

$email_para = 'placeholder@placeholder.com';
$asunto = 'Datos e imágenes del formulario';
$headers = array('Content-Type: text/html; charset=UTF-8');

$attachments = array();
$attachments[] = $_POST['wpcf-imagen-de-portada'];
foreach ($_POST['wpcf-galeria-de-imagenes'] as $file_path) {
$attachments[] = $file_path;
}

wp_mail($email_para, $asunto, $contenido, $headers, $attachments);
}
}

#2699902

I have achieved it!

It wasn't easy for me but I managed it, the problem I had is that the wp_mail() function expects the full local server path (for example: /home/user/public_html/wp-content/uploads/2024/05/image- example.jpg)

Then you have to work on that argument before inserting it into wp_mail(). I did it something like:

function url_to_path($url) {
$base_dir = ABSPATH;
$site_url = site_url('/');
$relative_path = str_replace($site_url, '', $url);
return $base_dir . $relative_path;
}

Thanks for the support