Discussion:
Help with wp_mail(), PHPMailer, and CC vs BCC
Mike Walsh
2013-10-08 21:24:12 UTC
Permalink
I am getting reports from a few users that my Email Users plugin is putting
recipient addresses in the CC header instead of the BCC header. I am
stumped as to how this is happening but I've had three reports in the past
24 hours.

Is there anyway to intercept PHPMailer from actually performing the final
send? What I'd like to do is let the plugin run normally right up to the
point where wp_mail() calls PHPMailer and then prevent PHPMailer from doing
the actual send. I'd then like to examine the headers in the PHPMailer
global instance to try and figure out what is going haywire.

I've looked through wp_mail() and the PHPMailer class and I don't see any
obvious way to do this so am hoping someone has had to do something similar
before. There is a reference in wp_mail() to a hook called
'phpmailer_init' but I haven't found out what it is used for nor when it is
called.

Mike
--
Mike Walsh - ***@gmail.com
Shea Bunge
2013-10-08 21:28:50 UTC
Permalink
wp_mail() is a pluggable function, so you can just copy it into a plugin
and modify it how you like. Your custom wp_mail() will be used instead of
the default function.
Post by Mike Walsh
I am getting reports from a few users that my Email Users plugin is putting
recipient addresses in the CC header instead of the BCC header. I am
stumped as to how this is happening but I've had three reports in the past
24 hours.
Is there anyway to intercept PHPMailer from actually performing the final
send? What I'd like to do is let the plugin run normally right up to the
point where wp_mail() calls PHPMailer and then prevent PHPMailer from doing
the actual send. I'd then like to examine the headers in the PHPMailer
global instance to try and figure out what is going haywire.
I've looked through wp_mail() and the PHPMailer class and I don't see any
obvious way to do this so am hoping someone has had to do something similar
before. There is a reference in wp_mail() to a hook called
'phpmailer_init' but I haven't found out what it is used for nor when it is
called.
Mike
--
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Regards,

Shea Bunge
http://bungeshea.com
Mike Walsh
2013-10-09 00:01:39 UTC
Permalink
I understand that wp_mail() is pluggable, in fact, I am concerned that may
be the source of these curious problems. I've been working with a user
for the last couple hours to chase this down and now it isn't happening any
more. She tells me all her plugins and themes are as they were earlier but
something doesn't pass the sniff test.

Is there a way to determine if wp_mail() has indeed been overloaded?

I was able to use the phpmailer_init filter to dump the status of the
PHPMailer instance just before mail is sent so that was helpful. It would
be nice if wp_mail() had a similar filter but unfortunately it does not. I
don't want to distribute a modified version of wp_mail() with my plugin
either as I don't need anything but the standard behavior.

Mike
Post by Shea Bunge
wp_mail() is a pluggable function, so you can just copy it into a plugin
and modify it how you like. Your custom wp_mail() will be used instead of
the default function.
Post by Mike Walsh
I am getting reports from a few users that my Email Users plugin is
putting
Post by Mike Walsh
recipient addresses in the CC header instead of the BCC header. I am
stumped as to how this is happening but I've had three reports in the
past
Post by Mike Walsh
24 hours.
Is there anyway to intercept PHPMailer from actually performing the final
send? What I'd like to do is let the plugin run normally right up to the
point where wp_mail() calls PHPMailer and then prevent PHPMailer from
doing
Post by Mike Walsh
the actual send. I'd then like to examine the headers in the PHPMailer
global instance to try and figure out what is going haywire.
I've looked through wp_mail() and the PHPMailer class and I don't see any
obvious way to do this so am hoping someone has had to do something
similar
Post by Mike Walsh
before. There is a reference in wp_mail() to a hook called
'phpmailer_init' but I haven't found out what it is used for nor when it
is
Post by Mike Walsh
called.
Mike
--
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Regards,
Shea Bunge
http://bungeshea.com
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Mike Walsh - ***@gmail.com
Thomas Scholz
2013-10-09 07:56:21 UTC
Permalink
Post by Mike Walsh
Is there a way to determine if wp_mail() has indeed been overloaded?
Use the Reflection API.
<http://www.php.net/manual/en/book.reflection.php>

$reflection = new ReflectionFunction( 'wp_mail' );
print $reflection->getFileName();

Thomas
Mike Walsh
2013-10-09 15:22:24 UTC
Permalink
This is perfect, thanks very much, it is exactly what I was looking for.

Mike
Post by Mike Walsh
Is there a way to determine if wp_mail() has indeed been overloaded?
Use the Reflection API.
<http://www.php.net/manual/en/**book.reflection.php<http://www.php.net/manual/en/book.reflection.php>
$reflection = new ReflectionFunction( 'wp_mail' );
print $reflection->getFileName();
Thomas
______________________________**_________________
wp-hackers mailing list
http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
--
Mike Walsh - ***@gmail.com
Loading...