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
This commit is contained in:
Peter Westwood 2008-10-16 20:57:49 +00:00
parent 6e4773588a
commit e99eff7d52
1 changed files with 13 additions and 2 deletions

View File

@ -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!