
Integrating SMTP into WordPress Without Using a Plug-in
- August 24, 2016
- Leave a comment
The wp_mail function is implemented using the PHPMailer class to send emails. By default, there is a hard coded $phpmailer->IsMail(); function call that enables the PHPMailer class to use native PHP mail function. This is why, the wp_mail function ultimately use PHP mail functions to send emails.
You can also setup PHPMailer to send email through SMTP using the phpmailer_init action. In this article, you will learn a simple way to integrate SMTP into WordPress without using any plug-in. The phpmailer_init action calls right before sending an email so that you can override all the parameters and functions associated with PHPMailer. You just need to pass PHPMailer object to the function and update all the parameters there.
1 2 3 4 5 6 7 8 9 10 11 |
function my_phpmailer_setup( PHPMailer $phpmailer ) { $phpmailer->Host = 'my.smpt.host.address'; $phpmailer->Port = 25; // Setup the port suggest by SMTP server $phpmailer->SMTPAuth = true; // Force SMTP to use username and password authentication $phpmailer->Username = 'username'; $phpmailer->Password = 'password'; $phpmailer->isSMTP(); // Do all the additional settings that are required } |
Hello,
Should add I this code to functions.php of theme?
Help me please!
Hello Serdar,
Yes, you have to put this code in your theme’s “function.php” file and write your details accordingly. And then call it in “phpmailer_init” WP action hook.
Thank you for contacting us. Please let us know if you need any further assistance.
Regards,
Ahmed | Associate Plugin Developer
Email: support@presstigers.com
Thank you for your help friend 🙂
Hello Ahmed,
I have developed a simple wordpress form builder plugin & i want to send an email to the specified address with the contents of the submitted from.
How can i do it.
Regards,
Sharath C B
Hello Sharath,
Please follow the instruction in the article. If you want further customization then please contact us at support@presstiger.com so that we can provide you the personalized support.
Regards,
PressTigers Support Team
Hello! Maybe, do you know, how can i add two email settings?
I have uses contact form 7 and woocommerce. And i want to send contact form emails from 1 mail (info@domain.com) and woocommerce emails from 2 mail (orders@domain.com).
Hello Roman,
It is one email account solution. If you want to add two accounts then please contact us at support@presstigers.com to avail of our services for these modifications.
Thank you for reaching us out. Let us know if we can assist you further.
Regards,
PressTigers Support Team
should i need to define the smtp port details in the wp_config.php file?
help me..
I need to send email, by using wp_mail () for the button click event in the plugin, and new to WordPress, how can i acheive this task? .Give me a guidance.
Hello Hema,
If you want to avail our services for these modifications then please contact us at support@presstigers.com
Thank you for reaching us out. Let us know if we can assist you further.
Regards,
PressTigers Support Team