How to send mail in WordPress using SMTP without using plugins
Step1: At first, Add this code into the wp-config.php
file of your WordPress website.
define( 'SMTP_USER', 'user@example.com' ); define( 'SMTP_PASS', 'smtp password' ); define( 'SMTP_HOST', 'smtp.example.com' ); define( 'SMTP_FROM', 'your@example.com' ); define( 'SMTP_NAME', 'your Name' ); define( 'SMTP_PORT', '25' ); define( 'SMTP_SECURE', 'tls' ); define( 'SMTP_AUTH', true ); define( 'SMTP_DEBUG', 0 );
Step2: Add the following lines of code the theme functions file (functions.php
).
add_action( 'phpmailer_init', 'send_smtp_email' ); function send_smtp_email( $phpmailer ) { $phpmailer->isSMTP(); $phpmailer->Host = SMTP_HOST; $phpmailer->SMTPAuth = SMTP_AUTH; $phpmailer->Port = SMTP_PORT; $phpmailer->Username = SMTP_USER; $phpmailer->Password = SMTP_PASS; $phpmailer->SMTPSecure = SMTP_SECURE; $phpmailer->From = SMTP_FROM; $phpmailer->FromName = SMTP_NAME; }