0

I already have made changes in both php.ini and sendmail.ini but still it doesn't work

php.ini

[mail function]

SMTP=smtp.gmail.com
smtp_port=25
sendmail_from = kaush3207@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=kaush3207@gmail.com
auth_password= 12345  
force_sender=kaush3207@gmail.com

OTP.php

    $from ="kaush3207@gmail.com";
    $to="soku2131@gmail.com";
    $subject="verify-account-otp";

    // Generating otp with php rand variable

    $otp=rand(100000,999999);
    $message=strval($otp);
    $headers="From: ".$from;

    $send=mail($to,$subject,$message,$headers);

    if($send){
     
        echo "OTP sent";
        
    }
    else
    {   
        echo "OTP not sent";
    }

It always gives "OTP not sent". I have also tried with port no. 587 and 465 but it doesn't work.

Gourav
  • 27
  • 7
  • You're better off using SMTP directly. It's safer, faster, and more reliable than using `mail()`. – Synchro May 01 '22 at 08:40
  • It's working when I disabled 2 step verification in google security and enable less secure app access. – Gourav May 01 '22 at 10:20
  • That won’t stay working for long as Google is discontinuing those options. Read about how to do it correctly in the PHPMailer troubleshooting guide. – Synchro May 01 '22 at 19:57

0 Answers0