Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to send mails in PHP contact form using 000webhost webmail [duplicate]

Tags:

php

email

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 = "[email protected]";
$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.
?>
like image 845
Mercury121 Avatar asked Nov 13 '22 06:11

Mercury121


1 Answers

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>
like image 192
Mehdi Karamosly Avatar answered Nov 14 '22 23:11

Mehdi Karamosly