From e99eff7d5286b9b2b0fa9c4c9b69c33e4f8df42d Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Thu, 16 Oct 2008 20:57:49 +0000 Subject: [PATCH] Add attachment support to wp_mail. Fixes #7787 props AaronCampbell. git-svn-id: https://develop.svn.wordpress.org/trunk@9213 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/pluggable.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 2a53eab387..1880926874 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -253,11 +253,15 @@ if ( !function_exists( 'wp_mail' ) ) : * @param string $subject Email subject * @param string $message Message contents * @param string|array $headers Optional. Additional headers. + * @param string|array $attachments Optional. Files to attach. * @return bool Whether the email contents were sent successfully. */ -function wp_mail( $to, $subject, $message, $headers = '' ) { +function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { // Compact the input, apply the filters, and extract them back out - extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers' ) ) ); + extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) ); + + if ( !is_array($attachments) ) + $attachments = explode( "\n", $attachments ); global $phpmailer; @@ -406,6 +410,13 @@ function wp_mail( $to, $subject, $message, $headers = '' ) { } } + error_log($attachments); + if ( !empty( $attachments ) ) { + foreach ( $attachments as $attachment ) { + $phpmailer->AddAttachment($attachment); + } + } + do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); // Send!