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',   '[email protected]' );    
    define( 'SMTP_PASS',   'smtp password' );       
    define( 'SMTP_HOST',   '' );    
    define( 'SMTP_FROM',   '[email protected]' ); 
    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->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;

Leave a Reply

Your email address will not be published. Required fields are marked *