0

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.

Nhan
  • 3,595
  • 6
  • 30
  • 38
phpLover
  • 155
  • 1
  • 2
  • 14
  • Here, try this solution from this [post](http://stackoverflow.com/questions/19132171/send-email-from-localhost-running-xammp-in-php-using-gmail-mail-server) – aomanansala Jan 21 '17 at 14:28
  • http://stackoverflow.com/questions/19132171/send-email-from-localhost-running-xammp-in-php-using-gmail-mail-server refer this too.... – prakash tank Jan 21 '17 at 14:29
  • not sure but does there need to be a colon after that Content-type? `Content-type: text/html;` I was looking at this line here `$headers[] = 'Content-type: text/html; charset=iso-8859-1'` on php.net and not sure if thats just because two commands on same line, or if necessary. So check that to make sure. – blamb Jan 21 '17 at 20:24

0 Answers0