-1

I am trying to send mail from localhost to my gmail. I am using windows 7. My mail() function is showing not any error on submit. Instead, on submit, a window appears and disappears suddenly even i can't see the window properly.

mail.php

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

if(mail($to, $subject, $body,$headers))
{
    echo 'Mail has send';

}

else
{
        echo "Email Not Found";
}

php.ini

1130 [mail function]
1131 ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
1132 SMTP = smtp.gmail.com
1133 smtp_port = 587
1134 sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=mygmail.com
auth_password=myPass
force_sender=mygmailgmail.com

2 Answers2

0

initialize all the variable in mail.php Here's an example:

$to       = 'sender_email_id_here@gmail.com';
$subject  = 'Testing';
$message  = 'Email Testing';
$headers  = 'From: your_emil_id_here@gmail.com' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=utf-8';
SattyamBhatt
  • 338
  • 2
  • 13
0

Because google keep your email secure and your php application or site is not secure according to google point of view .may be google is not giving your php code to access your email . you may have to check it .this is google statement below you can see
**

  • Less secure apps access

** View whether or not the selected user has access to less secure applications. You can enable access to less secure applications by going to Security > Basic Settings > Less Secure Apps Access and clicking Turn on. Access is assigned by Organizational Units and Group filters rather than by users

screen shot,

enter image description here

Imran Shad
  • 58
  • 13