title: How to choose between SMTP accounts in PHPMailer based on certain conditions?
body: <p>In my WordPress v6.0, I have configured sending SMTP mails (no-reply@example.com) through <code>$phpmailer</code> which is working fine.</p>
  <p>I want to use another SMTP email account (contact@example.com) for all custom contact forms communications.</p>
  <p>Sending contact form emails with <code>wp_mail()</code> as below:</p>
  <pre><code> wp_mail($form_to, $form_subject, $form_body, implode(&quot;\r\n&quot;, $form_headers));
  </code></pre>
  <p>How can I identify the above <code>wp_mail</code> and use particular SMTP account? Below is the code I have, without the real <code>if</code> condition to check:</p>
  <pre><code>// MAILER
  add_action('phpmailer_init', 'send_smtp_email', 10, 1);
  
  function send_smtp_email($phpmailer) {
  
      $phpmailer-&gt;isSMTP();
      $phpmailer-&gt;isHTML(true);
  
      if (wp_mail == &quot;contact_form&quot;) { // not a real condition, this is what I want to achieve
          $phpmailer-&gt;Host = 'smtp.example.com';
          $phpmailer-&gt;SMTPAuth = 'true';
          $phpmailer-&gt;Port = 465;
          $phpmailer-&gt;Username = 'contact@example.com';
          $phpmailer-&gt;Password = 'password1';
          $phpmailer-&gt;SMTPSecure = 'ssl';
          $phpmailer-&gt;From = 'contact@example.com';
          $phpmailer-&gt;FromName = 'Site Contact Form';
      } else {
          $phpmailer-&gt;Host = 'smtp.example.com';
          $phpmailer-&gt;SMTPAuth = 'true';
          $phpmailer-&gt;Port = 465;
          $phpmailer-&gt;Username = 'no-reply@example.com';
          $phpmailer-&gt;Password = 'password2';
          $phpmailer-&gt;SMTPSecure = 'ssl';
          $phpmailer-&gt;From = 'no-reply@example.com';
          $phpmailer-&gt;FromName = 'Site Mail';
      }
  }
  </code></pre>