WordPress is the most popular CMS in the globe to build a website. But there’s one question that how to configure SMTP on your wordpress without using any plugin? Many WordPress user struggle with this question.
In this article we will provide you a solution of "configure SMTP without any plugin" to configure SMTP on your wordpress website without using any plugin.
WordPress by default has added phpmailer library files with its core files so you can easily configure the SMTP without using any plugins. You will require to use phpmailer hooks function of the wordpress to setup SMTP without using any plugin.
I am here providing sample codes to configure SMTP without using any wordpress plugin. You will require to add given below code into your function.php file and update the access details like hostname, username, password and so on as per your site requirement.
Here’s an example of a basic configuration for SMTP (so phpmailer will be used instead of php’s mail()):
add_action( 'phpmailer_init', 'smtp_mailer_config', 10, 1); function smtp_mailer_config(PHPMailer $mailer){ $mailer->IsSMTP(); $mailer->Host = "smtp-dot-domain-dot-com"; // your SMTP server $mailer->Port = 25; $mailer->SMTPDebug = 2; // write 0 if you don't want to see client/server communication in page //$mailer->SMTPAuth = true; // Force it to use Username and Password to authenticate //$mailer->Username = 'yourusername'; //$mailer->Password = 'yourpassword'; // Additional settings… //$mailer->SMTPSecure = "tls"; // Choose SSL or TLS, if necessary for your server //$mailer->From = " "; //$phpmailer->FromName = "Your Name"; $mailer->CharSet = "utf-8"; }
If you are getting any issue during configured the SMTP then you can debug the issue by mail error logs.
Here’s an example of a basic error logging:
add_action('wp_mail_failed', 'smtplog_mailer_errors', 10, 1); function smtplog_mailer_errors( $wp_error ){ $fn = ABSPATH . '/mail.log'; // say you've got a mail.log file in your server root $fp = fopen($fn, 'a'); fputs($fp, "Mailer Error: " . $wp_error->get_error_message() ."\n"); fclose($fp); }
If you found answer helpful then Share and Follow Wordpress Learners Adda top get more useful post on wordpress.