1

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 =vskentos1@gmail.com
    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
auth_username=vskentos1@gmail.com
auth_password=mypassword
force_sender=vskentos1@gmail.com

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      = "vskentos2@gmail.com";
    $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 .

  • Does this answer your question? [Sending email with PHP from an SMTP server](https://stackoverflow.com/questions/14456673/sending-email-with-php-from-an-smtp-server) – Steven Penny Aug 04 '20 at 17:16
  • @StevenPenny Let me give a try – Vasilis Skentos Aug 04 '20 at 17:24
  • @StevenPenny If I use PHPMAILER I have to include a password inside my code . I am doing a college project and I cannot expose my gmail account password – Vasilis Skentos Aug 04 '20 at 17:33
  • Why you are not using PHPMailer and loading the configuration from a config file (.ini, .yml, .json) or through environment variables (e.g. with [PHP dotenv](https://github.com/vlucas/phpdotenv)? The configuration file can be excluded from your project, if you are using a version control like GIT. – Martin Aug 04 '20 at 18:36
  • @Martin I will try it . – Vasilis Skentos Aug 04 '20 at 18:44

0 Answers0