| 159 | | if( $headers == '' ) { |
|---|
| | 159 | global $phpmailer; |
|---|
| | 160 | error_log("mailing $subject\n", 0); |
|---|
| | 161 | if ( !is_object( $phpmailer ) ) { |
|---|
| | 162 | require_once(ABSPATH . WPINC . '/class-phpmailer.php'); |
|---|
| | 163 | require_once(ABSPATH . WPINC . '/class-smtp.php'); |
|---|
| | 164 | $phpmailer = new PHPMailer(); |
|---|
| | 165 | } |
|---|
| | 166 | |
|---|
| | 167 | $mail = compact('to', 'subject', 'message', 'headers'); |
|---|
| | 168 | $mail = apply_filters('wp_mail', $mail); |
|---|
| | 169 | extract($mail); |
|---|
| | 170 | |
|---|
| | 171 | if ( $headers == '' ) { |
|---|
| 165 | | return @mail($to, $subject, $message, $headers); |
|---|
| | 177 | $phpmailer->ClearAddresses(); |
|---|
| | 178 | $phpmailer->ClearCCs(); |
|---|
| | 179 | $phpmailer->ClearBCCs(); |
|---|
| | 180 | $phpmailer->ClearReplyTos(); |
|---|
| | 181 | $phpmailer->ClearAllRecipients(); |
|---|
| | 182 | $phpmailer->ClearCustomHeaders(); |
|---|
| | 183 | |
|---|
| | 184 | $phpmailer->FromName = "WordPress"; |
|---|
| | 185 | $phpmailer->AddAddress("$to", ""); |
|---|
| | 186 | $phpmailer->Subject = $subject; |
|---|
| | 187 | $phpmailer->Body = $message; |
|---|
| | 188 | $phpmailer->IsHTML(false); |
|---|
| | 189 | $phpmailer->IsMail(); // set mailer to use php mail() |
|---|
| | 190 | |
|---|
| | 191 | do_action_ref_array('phpmailer_init', array(&$phpmailer)); |
|---|
| | 192 | |
|---|
| | 193 | $mailheaders = (array) explode( "\n", $headers ); |
|---|
| | 194 | foreach ( $mailheaders as $line ) { |
|---|
| | 195 | $header = explode( ":", $line ); |
|---|
| | 196 | switch ( trim( $header[0] ) ) { |
|---|
| | 197 | case "From": |
|---|
| | 198 | $from = trim( str_replace( '"', '', $header[1] ) ); |
|---|
| | 199 | if ( strpos( $from, '<' ) ) { |
|---|
| | 200 | $phpmailer->FromName = str_replace( '"', '', substr( $header[1], 0, strpos( $header[1], '<' ) - 1 ) ); |
|---|
| | 201 | $from = trim( substr( $from, strpos( $from, '<' ) + 1 ) ); |
|---|
| | 202 | $from = str_replace( '>', '', $from ); |
|---|
| | 203 | } else { |
|---|
| | 204 | $phpmailer->FromName = $from; |
|---|
| | 205 | } |
|---|
| | 206 | $phpmailer->From = trim( $from ); |
|---|
| | 207 | break; |
|---|
| | 208 | default: |
|---|
| | 209 | if ( $line != '' && $header[0] != 'MIME-Version' && $header[0] != 'Content-Type' ) |
|---|
| | 210 | $phpmailer->AddCustomHeader( $line ); |
|---|
| | 211 | break; |
|---|
| | 212 | } |
|---|
| | 213 | } |
|---|
| | 214 | |
|---|
| | 215 | $result = @$phpmailer->Send(); |
|---|
| | 216 | error_log("mailing result $result\n", 0); |
|---|
| | 217 | return $result; |
|---|