1

it was 3 days, have the same problem, i need to spot my code, i got fail return with my code, this is my localhost configuration in, sendmail.ini, here the setting:

[sendmail]

smtp_server = smtp.gmail.com
smtp_port = 587
smtp_ssl = auto
error_logfile = error.log
debug_logfile = debug.log
auth_username = xxx@gmail.com
auth_password = xxx
force_sender = xxx@gmail.com

and i change my php.ini:

[mail function]

SMTP=smtp.gmail.com

smtp_port=587

sendmail_from = xxx@gmail.com

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

this is my php code :

<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");

$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];

$to=$email;

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

$headers = array("From: xxx@gmail.com",
    "Reply-To: " .$name. " <".$email.">",
    "X-Mailer: PHP/" . PHP_VERSION
);

$headers = implode("\r\n", $headers);

$test = mail($to, $subject, $message, $headers);
if($test)
{
echo "Email sent successfully !!";    
}
else
{
echo "fail!";
}
?>

1 Answers1

0

you should follow following step, It will help

  1. Login to your Google account.
  2. Go to the 'My Account' page and click Sign-in & security.
  3. turn On Allow less secure apps.

Thanks for explaining your error message.

Amit Senjaliya
  • 2,867
  • 1
  • 10
  • 24