wp_mail Allow Remote Attachments from CDN

I came across a problem with WP_Mail for sending form submissions with file attachments. Our site uses a CDN, so everything uploaded to the site, whether images and media by site builders or documents by users gets put on an external server.

This poses a problem for WP_Mail because it uses the PHPMailer addAttachment method to attach files, which expects local files. I was able to fix this by changing the line in wp_mail to use addStringAttachment, but of course modifying core files isn't really a fix. What is the right way to do this?

Thanks.

Topic wp-mail attachments cdn Wordpress

Category Web


Solved by Tom J Nowell's suggestion. Our form plugin fortunately has a filter before the data is passed to wp mail, so there I was able to swap the attachment url for one pointing to the temporary folder.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.