title: Wordpress Plugin Development: Override Default SMTP
body: <p>I want to override the default SMTP server settings provided by wordpress and have to use the same SMTP settings at multiple places in the plugin to send mails. </p>
  
  <p>The new SMTP server details would be provided by the user, through a form on wp-admin</p>
  
  <p>While googling about it, I came accross <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/class-phpmailer.php" rel="nofollow noreferrer">phpMailer</a>, and <a href="https://github.com/WordPress/WordPress/blob/master/wp-includes/class-smtp.php" rel="nofollow noreferrer">class-smtp.php</a> <br></p>
  
  <p>The possible solutions that I could think of <br>
   1. Create a global object for phpmailer class, and use it accross the plugin <br>
   2. Override the default wordpress SMTP server settings <br>
   3. Save the settings entered by the user in database and retrieve it while creating a PHPmailer object wherever I have to send mail. <br></p>
  
  <p>The problem I am facing with the above solutions are..</p>
  
  <p>1st Solution. I am not able to figure out how to achieve it. <br>
  2nd Solution: I could not find any resource on wordpress codex, that could explain on how to override default smtp settings.  <br>
  3rd Solution: is not productive enough.</p>
  
  <p>Also, I am trying to create a standalone plugin, so cannot create a dependency on any third party plugin. Though I have tried going through the source code of <a href="https://wordpress.org/plugins/wp-smtp/" rel="nofollow noreferrer">wp-smtp</a>, but could not figure out how to use the same settings at multiple places.</p>
  
  <p>I am using Tom Mcfarlin's Wordpress Boilerplate Plugin (<a href="https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate" rel="nofollow noreferrer">link</a>), in order to create a standard plugin file structure, so if someone can explain me a solution using the boilerplate, it would be really be useful and efficient.</p>
  
  <p><strong>EDITS:</strong> <br>
  I am uploading the file structure for better understanding.
  <br>
  <img src="https://i.stack.imgur.com/pyG15.png" alt="enter image description here">
  <br></p>
  
  <p>This is the form 
  <img src="https://i.stack.imgur.com/ryRSA.png" alt="enter image description here"></p>
  
  <p>The form values are succesfully retrieved at class-atf-admin.php
  <img src="https://i.stack.imgur.com/Kqk0W.png" alt="enter image description here"></p>
  
  <p><strong>I need to create a global variable in class-atf-admin.php, where I'll set the values received from the form and use it at files shown in the above figure.</strong></p>