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.
The new SMTP server details would be provided by the user, through a form on wp-admin
While googling about it, I came accross phpMailer, and class-smtp.php
The possible solutions that I could think of
1. Create a global object for phpmailer class, and use it accross the plugin
2. Override the default wordpress SMTP server settings
3. Save the settings entered by the user in database and retrieve it while creating a PHPmailer object wherever I have to send mail.
The problem I am facing with the above solutions are..
1st Solution. I am not able to figure out how to achieve it.
2nd Solution: I could not find any resource on wordpress codex, that could explain on how to override default smtp settings.
3rd Solution: is not productive enough.
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 wp-smtp, but could not figure out how to use the same settings at multiple places.
I am using Tom Mcfarlin’s WordPress Boilerplate Plugin (link), 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.
EDITS:
I am uploading the file structure for better understanding.
This is the form
The form values are succesfully retrieved at class-atf-admin.php
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.
Mkay, I am going to have a crack at option 1 (not 100% on the phpmailer naming though)
In your main plugin file, Based on this example code
For the variables from the users end, add the above to a shortcode and make insert the smtp details via shortcode perhaps. eg
[sendMail host="mail.yourdomain.com" port="26" username="yourname@yourdomain" password="yourpassword"]