Since a week ago, WordPress stopped to send normal emails upon new events like new user registration, new comments, and sucuri logs.

I tried everything but no luck, so i installed WP Mail SMTP to connect Gmail to my WordPress with Google API and it works fine.

But i have custom pages (Report and Request) that depends on default WordPress PHP mailer

so, how i integrate WP Mail SMTP inside these pages

here is an example of the report page

if($_GET['report']) { 
require_once "form/captacha.php";
$siteKey = get_option('pc_key');
$secret = get_option('pv_key');
$resp = null;
$error = null;
$reCaptcha = new ReCaptcha($secret);
if ($_POST["g-recaptcha-response"]) {
$resp = $reCaptcha->verifyResponse(
$_POST["g-recaptcha-response"] ); }
if ($resp != null && $resp->success) { 
$msg = "";
if ($_POST['action'] == "send") {
$vname = $_FILES['arch']['name'];
$vtemp = $_FILES['arch']['tmp_name'];
$rmailsend = get_option('reportemail');
$mail = new PHPMailer();
$mail->Host = "localhost";
$mail->From = $rmailsend;
$mail->FromName = __( "New Report", "demotheme" );
$mail->Subject = $_POST['videos'];
if ($vname != "") {
$mail->AddAttachment($vtemp, $vname); }
$body = "body"

and here is the "class.phpmailer.php" file https://justpaste.it/683q8

  • WordPress uses PHP Mailer also... just change your code to use wp_mail function instead of using it separately and it will send via SMTP plugin fine. :-) – majick Jan 24 at 18:06
  • Thnx for ur comment, but how to change the code to use wp_mail function – Ronan Jan 24 at 18:09
  • in the last lines of your code instead of the $mail object just put the variables as arguments, eg. wp_mail($emailto, $subject, $body, $headers=array(), $attachment); developer.wordpress.org/reference/functions/wp_mail – majick Jan 25 at 1:36
  • Although it takes me some time to figure it out. But i finally did it after you show me the right way, Thanks a lot. – Ronan Jan 25 at 5:31
  • awesome glad I could help. :-) – majick Jan 26 at 1:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.