admin管理员组文章数量:1417537
I need a way to query the sender's email address before delivery is attempted, and then set wp_mail arguments depending on the results.
So something like the following:
- If sender_email contains @domain then continue
- Else, if sender_email doesn't contain @domain, update wp_mail headers before sending
Use case is basically this:
I'm authenticating domain email using Postmark, so email will only send successfully if the sender's address matches an authenticated domain in my Postmark account.
What I want to do is create a check before it tries to send through Postmark, and if it's not an authenticated email address then send using wp_mail (WordPress's default mailing system) instead.
Or, put another way, ONLY send email through Postmark if it matches a specific domain or email address (which we can set manually).
I need a way to query the sender's email address before delivery is attempted, and then set wp_mail arguments depending on the results.
So something like the following:
- If sender_email contains @domain then continue
- Else, if sender_email doesn't contain @domain, update wp_mail headers before sending
Use case is basically this:
I'm authenticating domain email using Postmark, so email will only send successfully if the sender's address matches an authenticated domain in my Postmark account.
What I want to do is create a check before it tries to send through Postmark, and if it's not an authenticated email address then send using wp_mail (WordPress's default mailing system) instead.
Or, put another way, ONLY send email through Postmark if it matches a specific domain or email address (which we can set manually).
Share Improve this question asked Aug 1, 2019 at 16:33 jongoesonjongoeson 635 bronze badges 2 |1 Answer
Reset to default 1Perhpaps wp_mail
would be a suitable filter for this case as it is the first one to fire in wp_mail()
. So perhaps something as simple as this might work,
// For reference:
// $atts = array(
// 'to' => string,
// 'subject' => string,
// 'message' => string,
// 'headers' => string or array (I think),
// 'attachments' => array,
// );
function filter_wp_mail( $atts ) {
if ( false === strpos( '@domain', $atts['to'] ) ) {
$atts['headers'] .= "Postmark: not valid email\n";
}
return $atts;
}
add_filter( 'wp_mail', 'filter_wp_mail' );
版权声明:本文标题:wp mail - How do I set wp_mail argumentsmanually force wp_mail sending based on the sender's email address? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745273979a2651066.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_mail
filter andphpmailer_init
action that you could perhaps take a look at. – Antti Koskinen Commented Aug 2, 2019 at 21:59