5

I am using 000webhost webmail to receive emails using contact form but its not working.

contact.php

     <form  action="mailer.php" method="post">
<p>Name:</p>
<input type="text" name="name" />
<p>E-mail:</p>
<input type="text" name="email" />
<p>Subject:</p>
<input type="text" name="subject" />
<p>Message:</p>
<textarea name="message"></textarea></p>
<input class="send" type="submit" value="Send" name="submit">
</form>

mailer.php

     <?php

$to = "xxx@xxxxx.com";
$subject = "Support requested by ".$_POST['name'];
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$headers = 'From: '.$_POST['email'].'' . "\r\n" .
   'Reply-To: '.$_POST['email'].'' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

$body = $message;

@mail($to, $subject, $body, $headers );
header( 'Location:thankyou.php' ) ; //replace with landing page.
?>
Panagiotis Panagi
  • 9,927
  • 7
  • 55
  • 103
Mercury121
  • 123
  • 2
  • 2
  • 9
  • 1
    What part isn't working? The message isn't sent? You are receiving error messages? Have you checked your logs? – brbcoding May 02 '13 at 19:47
  • 2
    First and foremost, remove the "@" from "@mail" so you will see an error if there is one. – Tymoteusz Paul May 02 '13 at 19:49
  • i see the thankyou page but i dont recieve any email – Mercury121 May 02 '13 at 19:49
  • My first guess would be that your web host is rejecting outgoing mail from the from address you supplied... some restrict outgoing mail to your domain. – naththedeveloper May 02 '13 at 19:51
  • Is the `mail()` function returning true or false? If `true`, then it's something PHP doesn't know about (blackholed, blocked, etc.). If `false`, then it's likely not allowed from the server, or you have an error in your code somewhere. – Tarka May 02 '13 at 19:58

1 Answers1

1

Nothing wrong with your html I tried it. If you have chrome you can use the developer tool to debug and see if your requests are sent and if they are lending on the correct path :

enter image description here

In your mailer.php output the $_POST variable to make sure your data is landing there correctly,

echo "<pre>";
    var_dump($_POST);
echo "</pre>";

You may also need to validate your html :

<form  action="mailer.php" method="post">
  <p>Name:</p>
  <input type="text" name="name" >
  <p>E-mail:</p>
  <input type="text" name="email" >
  <p>Subject:</p>
  <input type="text" name="subject" >
  <p>Message:</p>
  <textarea name="message"></textarea>
  <input class="send" type="submit" value="Send" name="submit">
</form>
Mehdi Karamosly
  • 5,388
  • 2
  • 32
  • 50