admin管理员组文章数量:1290935
I'm working on developing a support website and I'm using Gravity Forms to handle the support ticket form. I have the form notification configured so that the "From" shows my client's email address instead of the email address from the SMTP.
I found some code to execute from my functions.php file that will change the default wp_mail()
if the "From" email doesn't match. Exactly what I want..:
add_filter('wp_mail_from', 'doEmailFilter');
add_filter('wp_mail_from_name', 'doEmailNameFilter');
function doEmailFilter($email_address){
if($email_address === "[email protected]")
return '[email protected]';
else
return $email_address;
}
function doEmailNameFilter($email_from){
if($email_from === "WordPress")
return 'Site Admin';
else
return $email_from;
}
I also found code that will run SMTP from functions.php:
add_action( 'phpmailer_init', 'send_smtp_email' );
function send_smtp_email( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = SMTP_HOST;
$phpmailer->SMTPAuth = SMTP_AUTH;
$phpmailer->Port = SMTP_PORT;
$phpmailer->Username = SMTP_USER;
$phpmailer->Password = SMTP_PASS;
$phpmailer->SMTPSecure = SMTP_SECURE;
$phpmailer->From = SMTP_FROM;
$phpmailer->FromName = SMTP_NAME;
}
Update 6/6/21, Clarifies the question and updates the code: I tried to do this (thanks Paul G.):
add_filter('wp_mail_from', 'doEmailFilter');
function doEmailFilter($email_address){
if($email_address === "[email protected]")
return '[email protected]';
else
return $email_address;
}
$emailfilter = 'doEmailFilter';
add_action( 'phpmailer_init', function ( $phpmailer ) use ( $emailfilter ) {
if ( $emailfilter === '[email protected]' ) {
$phpmailer->Mailer = 'smtp';
$phpmailer->Host = SMTP_HOST;
$phpmailer->SMTPAuth = SMTP_AUTH;
$phpmailer->Port = SMTP_PORT;
$phpmailer->Username = SMTP_USER;
$phpmailer->Password = SMTP_PASS;
$phpmailer->SMTPSecure = SMTP_SECURE;
$phpmailer->From = SMTP_FROM;
$phpmailer->FromName = SMTP_NAME;
}
else
return $emailfilter;
// any other case would not change the sending server
}
);
I have a form with two email notifications that get sent when the form is sent.
The first notification goes to my main inbox as a standard admin notification and uses the "[email protected]" as the "From", which should use the SMTP. This notification represents any email that gets sent from the website that is intended for my customers.
The second goes to another inbox that I own, but it swaps out the "From" with what's in the form. This will NOT use the SMTP, and I want that. It's more of an internal email that gets sent to an inbox that I have access to. The inbox is only meant to pipe emails into another system.
Both emails send, but the email with [email protected] in the "From" does not go through the SMTP.
How can it be fixed so only emails with [email protected] in "From" gets sent through the SMTP?
本文标签: phpRunning SMTP Conditionally
版权声明:本文标题:php - Running SMTP Conditionally 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741519256a2383080.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论