Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress wp_mail with attachment (with meaningful names)

How to use wp_mail function to send attachments with custom names for the attached files.

As of now email is getting delivered with attachment but name of files are same as physical file name.

I can't rename the files as we have lots of other references, but I want to send those files with some meaningful name.

like image 598
Kuldeep Singh Avatar asked Nov 25 '25 07:11

Kuldeep Singh


2 Answers

wp_mail doesn't support rename the attachment when sending emails. The one way to change names of sending files is copying this files with new names, attach new files to the email and delete this files after sending email.

like image 133
QArea Avatar answered Nov 27 '25 23:11

QArea


Thanks QArea for your response. I found the place though, one need to edit the wp-includes/pluggable.php wp_mail function for processing attachment, It should look like this

    if ( !empty( $attachments ) ) {
            foreach ( $attachments as $name => $attachment ) {
                    try {
                            $phpmailer->AddAttachment($attachment, $name);
                    } catch ( phpmailerException $e ) {
                            continue;
                    }
            }
    }
like image 45
Kuldeep Singh Avatar answered Nov 27 '25 21:11

Kuldeep Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!