0

Hi guys i'm having a issue i hope you guys can help with, i'm typing in all the fields and then upon pressing submit i'm getting just "Error!" on my screen.

Please see the code:

HTML

<h2 class="formhead">Contact Form</h2>
<br>
  <form class="form" action="mail.php" method="POST">

    <p class="name">
        <input type="text" name="name" id="name" placeholder="John Doe" />
        <label for="name">Name</label>
    </p>
<br>
    <p class="email">
        <input type="text" name="email" id="email" placeholder="mail@example.com" />
        <label for="email">Email</label>
    </p>
<br>
    <p class="number">
        <input type="text" name="number" id="number" placeholder="0774XXXXXXX" />
        <label for="name">Contact Number</label>
    </p>
<br>
    <p class="web">
        <input type="text" name="web" id="web" placeholder="www.example.co.uk" />
        <label for="name">Website</label>
    </p>
<br>
    <p class="message">
        <textarea name="message" id="message" placeholder="Write something to us" /> </textarea>
    </p>
<br>
    <p class="submit">
        <input type="submit" value="Send"/>
    </p>
  </form>

PHP

<?php $name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$website = $_POST['web'];
$formcontent="From: $name \n Contact: $number \n Website: $web \n Message: $message";
$recipient = "enquiries@c(hidden)y.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email ";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>

Any help would be much appreciated!

Thanks

Sam

Metexora
  • 66
  • 1
  • 7
  • 2
    You get `Error!` because that's the "or die" part of your mail statement. switch that to display the actual error. – Digital Chris Jan 05 '14 at 23:14
  • @DigitalChris I'm guessing its `die("Error!");` – Scuzzy Jan 05 '14 at 23:15
  • Add specific die messages, specifically for development. For example: die("Error a"); die("Error b"); – ilarsona Jan 05 '14 at 23:16
  • @Scuzzy edited before you could reply :p – Digital Chris Jan 05 '14 at 23:17
  • 1
    Your `mail()` function just fails. Check your *php_error.log* for more details. You might try to remove the `\r\n` on `$mailheader`, as you don't have multiple extra headers. – Maen Jan 05 '14 at 23:19
  • 1
    also some of your `$_post` vals don't match your `HTML`. Should be, `$message = $_POST['text']; $website = $_POST['web'];` – Bryan Elliott Jan 05 '14 at 23:22
  • To debug this, put `php_value display_errors Off` in your .htaccess file (assuming you're using Apache). Or, if you'd rather edit PHP.ini, find "error_reporting" and set it to "E_ALL"; find "display_errors" and set it to "On". – sheng Jan 05 '14 at 23:26
  • 1
    @ilarsona Hey i'm a newbie to PHP, how would the multiple errors be coded in a little bit more depth, just an example would suffice. Much appreciated thankyou – Metexora Jan 05 '14 at 23:27
  • @Bigood removed the \r\n thanks – Metexora Jan 05 '14 at 23:28
  • @ShengSlogar Hey thanks for the reply, i did this in the .hta and i'm now getting the error Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@c(hidden)y.co.uk and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. – Metexora Jan 05 '14 at 23:31
  • @Metexora Ahh. My bad. There's a setting in Apache's config file that allows htaccess files to control things. Try the PHP.ini method. If that doesn't work, I'll try and give you code to allow htaccess files to work. :) – sheng Jan 05 '14 at 23:36
  • @ShengSlogar I'm not too sure what or where a PHP.ini file is O:) – Metexora Jan 05 '14 at 23:39
  • @Metexora Is this your personal server? – sheng Jan 05 '14 at 23:42
  • no i'm using a paid hosting service webhosting.uk – Metexora Jan 05 '14 at 23:58
  • @Metexora Rats! See this: http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php Seems like you put `error_reporting(-1); ini_set('display_errors', 'On');` in your PHP code. – sheng Jan 06 '14 at 00:00

2 Answers2

3

Your script always reporting 'Error!' because the mail() function always fails. That's because some index you're using in the php file doesn't match to the input names in your form:

Change these:

$website = $_POST['website'];

to:

$website = $_POST['web'];

Or change it in your form.

Also you have to specify a name for the message textarea:

<textarea name="message" id="message" placeholder="Write something to us" />

This may fail again if it can't connect to mailserver. This is probably you're case if The SMTP is Disabled.

rullof
  • 7,124
  • 6
  • 27
  • 36
0

As per my comment, here's an example of a better die statement:

<?
$your_function or die("Error! a") // Just replace the letter a with anything. It serves as a simple link to your function that only you know.  so you can go back and check it
ilarsona
  • 436
  • 4
  • 13
  • You should let it as a comment, as it's definitively a comment! – Maen Jan 05 '14 at 23:36
  • do you mean such as die("Error! $name") die ("Error! $web") etc? – Metexora Jan 05 '14 at 23:40
  • Yes I knew, I just wanted it to stand out. Guess I could have done bold – ilarsona Jan 05 '14 at 23:41
  • @Metexora It can be whatever you want... it just serves to you as a pinpoint... "it failed here" – ilarsona Jan 05 '14 at 23:42
  • How does the error indicate what part of the form has failed with just any text? – Metexora Jan 05 '14 at 23:45
  • Once you say "or die" it spits out an error message. Yours are all the same, and you don't know where it failed. By putting in something unique (the letters are just an idea), you can easily know where it failed and look deeper into why, instead of trying to figure out exactly where. – ilarsona Jan 05 '14 at 23:48
  • like this?> Thankyou by the way $mailheader = "From: $email "; mail($recipient or die("Error! Recipient"), $subject or die("Error! Subject"), $formcontent or die("Error! Mail Body"), $mailheader or die("Error! Mail Header"); echo "Thank You!" . " -" . " Return Home"; – Metexora Jan 05 '14 at 23:55