Vasilis Skentos
Vasilis Skentos

Reputation: 21

unable to send email using php from localhost

I'm trying to send an email to an account using php and I am running a xampp server so I am using localhost to send an email . I have been trying all day to do this and I have checked many posts here without finding an answer . What I've tried :

PHP.INI (Every other line in this function is commented with ;)

 [mail function]
    SMTP=smtp.gmail.com
    smtp_port =465
    sendmail_from [email protected]
    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe" -t" 

SENDMAIL.INI (Every other line is also commented with ;)

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=465
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=mypassword
[email protected]

I've also tried changing smtp_port = 587 which still didn't work and I also changed ;smtp_ssl=auto in SENDMAIL.INI to smtp_ssl = tls when I changed the port to 587 with no result so I went back to ;smtp_ssl=auto and smpt_port=465 which I have included above . I restart xampp server whenever I make a change to the files . I have also allowed less secure apps to have access by configuring the security of my google account . My php code to send an email when running the file through localhost (works but the email is never sent )

<?php
    
    $to      = "[email protected]";
    $subject = "Test email";
    $message = "hello";

    mail($to,$subject,$message);

    if(mail($to, $subject, $message)){
        echo "email was sent to $to"; //this line is printed when I run localhost 
    }else{
        echo "fail";
    } 

    
?>
    

I would appreciate your help with this . Thank you in advance .

Upvotes: 1

Views: 56

Answers (0)

Related Questions