0

I am using XAMPP Version: 1.8.3 When I test the page I get no errors, mail() function return false. My code is as below.

<?php

try {
    $to = "***@gmail.in";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "***@gmail.com";
    $headers = "From:" . $from;
    $res = mail($to, $subject, $message, $headers);

    if ($res) {
        echo "<h4>Mail Sent.</h4>";
    } else {
        var_dump($res);
        echo "<h3>Mail not sent...</h3>";
    }
} catch (Exception $ex) {
    print_r($ex);
}
?>

sendmail.ini file changes

hostname=localhost
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
auth_username=****@gmail.com
auth_password=****
force_sender=****@gmail.com

php.ini file changes

SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = ***@gmail.com
sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\" -t"
;sendmail_path="D:\xampp\mailtodisk\mailtodisk.exe"
  • If there is no messages at all, you probably have a 500 error. This means the PHP is not running at all due to a syntax error or other issue – GrumpyCrouton Jun 13 '18 at 12:51
  • Have you tried sending an email message via a command line client using your setup? That often helps to identify issues. Next step would be to run your php script from the command line too instead of behind a http server. All only if you _really_ do not get any errors. Where have you checked for those errors? Does your http server's error log file _really_ contain nothing? Then what are your error logging settings in php? – arkascha Jun 13 '18 at 12:54
  • @arkascha mail() function return false, i dont know where error file is creating as am a begginer in php – mohitlandge Jun 13 '18 at 13:03
  • What `send()` function? Your code only shows a call to `mail()`... – arkascha Jun 13 '18 at 13:04
  • sorry its mail() function – mohitlandge Jun 13 '18 at 13:06
  • 2
    XAMPP is nothing but a combination of well known and documented standard components, among those php and the apache http server. That http server writes some log files, one is the error log file. That file _always_ is the first place to look for issues, you _can not_ develop in php in a web environment without monitoring that log file. That would be like flying in a narrow cave with your eyes blind folded: possible, but certainly not a good idea. Check your configuration for that log file, you look for the command `ErrorLog`. – arkascha Jun 13 '18 at 13:06

0 Answers0