-1

I am working on simple website but facing some problems with contact form, I try all type of settings but Its didnt work.

The problem is When I fill form and press submit button then It will be shows "Message sent successfully" But I cant receive any mail to my mail ID.

So What Can I do...???

My PHP CODE: file name is "mail.php"

<?php
  echo '<html xmlns="http://www.w3.org/1999/xhtml">';
  echo '<head>';
  echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
  echo '<title>';
  echo $title;
  echo '</title>';
  echo '</head>';
  echo '<body>';  

$to = "anup.karanjkar08@gmail.com;
$subject = $_REQUEST['Name'] + "Sent a Mail";
$message = $_REQUEST['Message'] ;
$from = $_REQUEST['Email'] ;
$headers = "From:" . $from;
$a= mail($to,$subject,$message);
if ($a) {
  echo "Message sent successfully";
}
else
{
  echo "Sorry there is an error.";
}
echo '</body>';
echo '</html>';

?>

My HTML CODE

<form name="contact_to_infrasure" id="infrasure"  action="mail.php" method="POST">
          <div class="row-fluid">
            NAME<br><input  type="text" name="Name">
          </div>
          <div class="row-fluid">
            EMAIL<br><input  type="text" name="Email"><br>
          </div>
          <div class="row-fluid">
            MESSAGE<br><textarea rows="5" style="width: 60%"  name="Message"></textarea><br>
          </div>
          <div class="row-fluid">
           <!--  <input class="span3" type="submit" value="SEND MESSAGE"> -->
          <button class="btn" type="submit" value="Submit" onClick="">SEND MESSAGE</button> 
          </div>
      </form>

Please Help Me...!!!

Andy
  • 29,707
  • 9
  • 41
  • 58

2 Answers2

4

First add ending " in this line.

$to = "anup.karanjkar08@gmail.com";

Then try to run if it works.

Check with hosting provider that mail function in php is working.

Maz I
  • 3,664
  • 2
  • 23
  • 38
0

changed these lines, concatination used in php is . not +, + used in javscript $subject = $_REQUEST['Name'] . "Sent a Mail";

        <?php
          echo '<html xmlns="http://www.w3.org/1999/xhtml">';
          echo '<head>';
          echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
          echo '<title>';
          echo $title;
          echo '</title>';
          echo '</head>';
          echo '<body>';  

            $to = "anup.karanjkar08@gmail.com";
            $subject = $_REQUEST['Name'] . "Sent a Mail"; // changed this line  removed + 
            $message = $_REQUEST['Message'] ;
            $from = $_REQUEST['Email'] ;
            $headers = "From:" . $from;
            $a= mail($to,$subject,$message, $headers); // added headers here
            if ($a) {
              echo "Message sent successfully";
            }
            else
            {
              echo "Sorry there is an error.";
            }
            echo '</body>';
            echo '</html>';

        ?>

Reason for mail not sending,

ISP Blocks

An increasing number of ISP’s are blocking port 25, the port used to send email. Many of the major ISP’s, including NetZero, MSN, Earthlink, AT&T, Comcast and Verizon, block port 25 in an attempt to control spam. If your ISP blocks port 25, then you will be unable to send email out of your server. This is not a server problem but a direct block by your ISP. We can often work around these blocks by configuring your mail server to listen to additional ports.

Ref: http://www.rackaid.com/resources/cannot-send-email-how-to-fix-email-sending-and-receiving-errors/

Krish R
  • 22,583
  • 7
  • 50
  • 59