Use different phpmailer for some of my customers
-
Hi, I have a real estate website where agents can send properties to people who invest in this kind of properties.
However, some of the agents want to use their own email address sending the real estate data to the investors. So they have the possibility to store their own SMTP credentials in a woocommerce setting, which I implemented in the frontend this afternoon.
Now what I am trying to achieve is – in case an agent wants to use his own SMTP settings when distributing a property – to change the SMTP settings for outgoing mails from this specific agent.
That’s what I got, but unfortunally, the SMTP settings are not being overwritten, although the current_user_id()-agent has the SMTP user meta field filled out correctly using the woocommerce setting I mentioned above:
What might be an approach / hook / filter that might work to overwrite the phpmailer settings under specific circumstances?
$agent_id = get_current_user_id(); // returns false, if agent has no own SMTP settings, returns an array from agents user meta data with the SMTP settings if he wants to use custom SMTP setting $possiblearray = use_own_mail_account($agent_id); if(is_array($possiblearray)) { // agent wants to use own SMTP settings $smtp_host = $smtpinfos["host"]; $smtp_port = $smtpinfos["port"]; $smtp_username = $smtpinfos["nutzername"]; $smtp_password = $smtpinfos["nutzerpasswort"]; $smtpsecure = $smtpinfos["verschluesselung"]; $smtpfrom = $smtpinfos["frommail"]; $smtpfromname = $smtpinfos["fromname"];; // filter to overwrite / change the default SMTP settings for the next mail add_filter('wp_mail_smtp_custom_options', function($phpmailer) use ($smtp_host, $smtp_port, $smtp_username, $smtp_password, $smtpsecure, $smtpfrom, $smtpfromname) { $phpmailer->isSMTP(); $phpmailer->Host = $smtp_host; $phpmailer->SMTPAuth = true; $phpmailer->Username = $smtp_username; $phpmailer->Password = $smtp_password; $phpmailer->SMTPSecure = $smtpsecure; $phpmailer->Port = $smtp_port; $phpmailer->From = $smtpfrom; $phpmailer->FromName = $smtpfromname; }); } // Send a test mail wp_mail("[email protected]", "this is a test mail", ""); // remove filter again remove_filter('wp_mail_smtp_custom_options', false);
- The topic ‘Use different phpmailer for some of my customers’ is closed to new replies.