有条件的支票我可以申请吗phpmailer_init
或awp_mail
用于应用自定义的参数phpmailer_init
SMTP设置仅在特定wp_mail
行动或行为phpmailer_init
是否始终在站点范围内运行?
如何仅在某些‘wp_mail’操作上使用‘phpmaeller_init’SMTP设置?
1 个回复
最合适的回答,由SO网友:TheDeadMedic 整理而成
phpmailer_init
每次都会开火wp_mail()
调用-但是,您可以有条件地如下挂接/取消挂接:
function wpse_224496_phpmailer_init( $phpmailer ) {
// SMTP setup
// Always remove self at the end
remove_action( \'phpmailer_init\', __function__ );
}
function wpse_224496_wp_mail( $mail ) {
// Example: only SMTP for emails addressed to foo@example.com
if ( $mail[\'to\'] === \'foo@example.com\' )
add_action( \'phpmailer_init\', \'wpse_224496_phpmailer_init\' );
// Example: only SMTP for subject "Foo"
if ( $mail[\'subject\'] === \'Foo\' )
add_action( \'phpmailer_init\', \'wpse_224496_phpmailer_init\' );
// Other properties
$mail[\'message\'];
$mail[\'headers\']; // Could be string or array
$mail[\'attachments\']; // Could be string or array
return $mail;
}
add_filter( \'wp_mail\', \'wpse_224496_wp_mail\' );