I am trying to send email using localhost
(XAMPP v3.2.1). For that I need to reconfigure php.ini
and sendmail.ini
file. So far what I have done is, I changed the following in the corresponding files.
In php.ini
I have changed to :
extension=php_openssl.dll (I Remove the semicolon from beginning)
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
And in sendmail.ini
file I have changed
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com
For Testing purpose I have written an index.php
file like this:
<!DOCTYPE html>
<html>
<head>
<title>Sending HTML email using PHP</title>
</head>
<body>
<?php
$to = "testMailId@gmail.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:senderMailId @gmail.com \r\n";
$header .= "senderMailId @gmail.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to, $subject, $message, $header);
if($retval == true ) {
echo "Message sent successfully...";
} else {
echo "Message could not be sent...";
}
?>
</body>
</html>
But the result is showing that message could not be sent. I don’t know if there is any wrong with configuration or code? Please help.