Make WordPress Core

Changeset 9213


Ignore:
Timestamp:
10/16/2008 08:57:49 PM (15 years ago)
Author:
westi
Message:

Add attachment support to wp_mail. Fixes #7787 props AaronCampbell.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/pluggable.php

    r9200 r9213  
    254254 * @param string $message Message contents
    255255 * @param string|array $headers Optional. Additional headers.
     256 * @param string|array $attachments Optional. Files to attach.
    256257 * @return bool Whether the email contents were sent successfully.
    257258 */
    258 function wp_mail( $to, $subject, $message, $headers = '' ) {
     259function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
    259260    // Compact the input, apply the filters, and extract them back out
    260     extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers' ) ) );
     261    extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message', 'headers', 'attachments' ) ) );
     262
     263    if ( !is_array($attachments) )
     264        $attachments = explode( "\n", $attachments );
    261265
    262266    global $phpmailer;
     
    404408        foreach( (array) $headers as $name => $content ) {
    405409            $phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
     410        }
     411    }
     412
     413    error_log($attachments);
     414    if ( !empty( $attachments ) ) {
     415        foreach ( $attachments as $attachment ) {
     416            $phpmailer->AddAttachment($attachment);
    406417        }
    407418    }
Note: See TracChangeset for help on using the changeset viewer.