/** * mailusers_fix_return_path() * * Fix the bounce (return path) setting if specified. The return * path header isn't recognized correctly in some (most?) cases. * * @param $mailer mixed PHPMailer instance * @see https://wordpress.org/support/topic/bounced-email-testing * * From the WordPress class-phpmailer.php file: * * @deprecated Email senders should never set a return-path header; * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything. * @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference */ function mailusers_fix_return_path($phpmailer) { $return_path = mailusers_get_send_bounces_to_address_override(); if (!empty($return_path)) { $phpmailer->addReplyTo($return_path); } }
?> <br /><b><i><?php _e('Note: Invalid email addresses are not saved.', MAILUSERS_I18N_DOMAIN); ?> </i></b></small></i></div></td> </tr> <tr> <th scope="row" valign="top"> <label for="send_bounces_to_address_override"><?php _e('Send Bounces To Email<br/>Address Override', MAILUSERS_I18N_DOMAIN); ?> </th> <td> <input type="text" name="mailusers_send_bounces_to_address_override" style="width: 235px;" value="<?php echo format_to_edit(mailusers_get_send_bounces_to_address_override()); ?> " size="80" id="from_sender_address_override"/><br/><div style="width: 90%;"><i><small><?php _e('An email address that can be used in place of the logged in user\'s email address to receive bounced email notifications.', MAILUSERS_I18N_DOMAIN); ?> <br /><b><i><?php _e('Note: Invalid email addresses are not saved.', MAILUSERS_I18N_DOMAIN); ?> </i></b></small></i></div></td> </tr> <tr> <th scope="row" valign="top"> <label for="mailusers_default_body"><?php _e('Default<br/>Notification Body', MAILUSERS_I18N_DOMAIN); ?>
/** * Delivers email to recipients in HTML or plaintext * * Returns number of recipients addressed in emails or false on internal error. */ function mailusers_send_mail($recipients = array(), $subject = '', $message = '', $type = 'plaintext', $sender_name = '', $sender_email = '') { $headers = array(); $base64 = mailusers_get_base64_encode() == 'true'; $omit = mailusers_get_omit_display_names() == 'true'; // Default the To: and Cc: values to the send email address $to = $omit ? $sender_email : sprintf('%s <%s>', $sender_name, $sender_email); $cc = sprintf('Cc: %s', $to); $num_sent = 0; // return value if (empty($recipients)) { return $num_sent; } if ('' == $message) { return false; } // Cc: Sender? $ccsender = mailusers_get_copy_sender(); // Return path defaults to sender email if not specified $return_path = mailusers_get_send_bounces_to_address_override(); if ($return_path == '') { $return_path = $sender_email; } // Build headers $headers[] = $omit ? sprintf('From: %s', $sender_email) : sprintf('From: "%s" <%s>', $sender_name, $sender_email); $headers[] = sprintf('Return-Path: <%s>', $return_path); $headers[] = $omit ? sprintf('Reply-To: %s', $sender_email) : sprintf('Reply-To: "%s" <%s>', $sender_name, $sender_email); $headers[] = 'MIME-Version: 1.0'; if (mailusers_get_add_x_mailer_header() == 'true') { $headers[] = sprintf('X-Mailer: PHP %s', phpversion()); } $subject = stripslashes($subject); $message = stripslashes($message); $footer = mailusers_get_footer(); if ('html' == $type) { if (mailusers_get_add_mime_version_header() == 'true') { $headers[] = 'MIME-Version: 1.0'; } $headers[] = sprintf('Content-Type: %s; charset="%s"', get_bloginfo('html_type'), get_bloginfo('charset')); $mailtext = "<html><head><title>" . $subject . "</title></head><body>" . $message . $footer . "</body></html>"; } else { if (mailusers_get_add_mime_version_header() == 'true') { $headers[] = 'MIME-Version: 1.0'; } $headers[] = sprintf('Content-Type: text/plain; charset="%s"', get_bloginfo('charset')); $message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message); $message = preg_replace('|&|', '&', $message); $mailtext = wordwrap(strip_tags($message . "\n" . $footer), 80, "\n"); } // Base64 Encode email? if ($base64) { //$subject = "=?UTF-8?B?" . base64_encode($subject) . "?="; $headers[] = "Content-Transfer-Encoding: base64"; //$mailtext = base64_encode($mailtext); } // If unique recipient, send mail using TO field. //-- // If multiple recipients, use the BCC field //-- $bcc = array(); $bcc_limit = mailusers_get_max_bcc_recipients(); if (count($recipients) == 1) { $recipient = reset($recipients); // reset will return first value of the array! if (mailusers_is_valid_email($recipient->user_email)) { $to = $omit ? $recipient->user_email : sprintf('%s <%s>', $recipient->display_name, $recipient->user_email); if ($ccsender) { $headers[] = $cc; } if (MAILUSERS_DEBUG) { mailusers_preprint_r($headers); mailusers_debug_wp_mail($to, $subject, $mailtext, $headers); } do_action('mailusers_before_wp_mail'); if ($base64) { @wp_mail($to, sprintf("=UTF-8?B?%s?=", base64_encode($subject)), base64_encode($mailtext), $headers); } else { @wp_mail($to, $subject, $mailtext, $headers); } do_action('mailusers_after_wp_mail'); $num_sent++; } else { echo '<div class="error fade"><p>' . sprintf(__('The email address (%s) of the user you are trying to send mail to is not a valid email address format.', MAILUSERS_I18N_DOMAIN), $recipient->user_email) . '</p></div>'; return $num_sent; } return $num_sent; } elseif ($bcc_limit != 0 && count($recipients) > $bcc_limit) { $count = 0; $sender_emailed = false; // Make sure there are no duplicates which can result // if/when the user selects both roles and users as // the recipients. foreach ($recipients as $key => $value) { $recipients[$key] = $recipients[$key]->user_email; } $recipients = array_unique($recipients); foreach ($recipients as $recipient) { if (!mailusers_is_valid_email($recipient)) { continue; } if (empty($recipient) || $sender_email == $recipient) { continue; } if ($bcc_limit == -1) { //$to = ($omit) ? $recipient->user_email : sprintf('%s <%s>', $recipient->display_name, $recipient->user_email) ; $to = $recipient; } else { $bcc[] = sprintf('Bcc: %s', $recipient); } $count++; // Use abs() of bcc_limit to account for -1 setting if (abs($bcc_limit) == $count || $num_sent == count($recipients) - 1) { if (MAILUSERS_DEBUG) { mailusers_debug_wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc)); } do_action('mailusers_before_wp_mail'); if ($base64) { @wp_mail($to, sprintf("=UTF-8?B?%s?=", base64_encode($subject)), base64_encode($mailtext), array_merge($headers, $bcc)); } else { @wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc)); } do_action('mailusers_after_wp_mail'); $count = 0; $bcc = array(); } $num_sent++; } } else { if ($ccsender) { $headers[] = $cc; } foreach ($recipients as $key => $value) { $recipients[$key] = $recipients[$key]->user_email; } $recipients = array_unique($recipients); foreach ($recipients as $recipient) { if (!mailusers_is_valid_email($recipient)) { echo '<div class="error fade"><p>' . sprintf(__('Invalid email address ("%s") found.', MAILUSERS_I18N_DOMAIN), $recipient) . '</p></div>'; continue; } if (empty($recipient) || $sender_email == $recipient) { continue; } $bcc[] = sprintf('Bcc: %s', $recipient); $num_sent++; } if (MAILUSERS_DEBUG) { mailusers_preprint_r(array_merge($headers, $bcc)); mailusers_debug_wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc)); } do_action('mailusers_before_wp_mail'); if ($base64) { @wp_mail($to, sprintf("=UTF-8?B?%s?=", base64_encode($subject)), base64_encode($mailtext), array_merge($headers, $bcc)); } else { @wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc)); } do_action('mailusers_after_wp_mail'); } return $num_sent; }