Failed to send email in wordpress custom plugin with SMTP plugin configured

1.5k views Asked by At

I have configured the SMTP and its sending email properly. I have to build a custom plugin that actually sends email notification on the certain event triggers. I am using the WP Mail SMTP plugin. I don't want to configure anything in my plugin. I just only want to extend their functionality and send emails. But I am failing to do that. I have written something like this

add_action( 'plugins_loaded', 'renderHTML' );
function renderHTML(){
    $to = '[email protected]';
    $subject = 'Test';
    $message = "Demo Message";
    $headers='';
    wp_mail($to, $subject, $message, $headers);
}

Kindly help what should be the way out for this.

1

There are 1 answers

9
Mitesh K On

this is my working code

function sendEmail($name,$email,$message,$subject)
{
    global $signature;
    $message .= "<br>" . $signature; 
 
    $admin = get_option('admin_email');
    $to = $email;
    $headers = 'Content-Type: text/html; charset=UTF-8';
    $headers .= "From: . $admin . \r\n" ;
    $headers .= "Reply-To: . $admin . \r\n" ;
  

    $sent = wp_mail($to, $subject, $message, $headers);

    if($sent)
        return true;
    else
        return false;

}