-3

I have a php contact form which I developed from this forum, the form gets a customers name, email and contact number from a website however, I'm getting several errors saying; undefined index name on line 34, the same error is present for a number of other variables also, I'm wondering if I could have some help resolving this issue?

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $Contact_Number = $_POST['contact number'];
    $from='From:Client';
    $to='reece@designthink.co.uk';
    $subject='Claremont Holding Page Enquiry';
    $body = "From: $name\n E-Mail: $email\n Contact Number:\n $Contact_Number";

if($_POST['submit'])
{
    if(mail($to, $subject,$body,$from))
    {
        echo '<p>Message sent!</p>';
    }
    else
    {
        echo '<p> something went wrong, please try again!</p>';
    }

}

?>



<form method = "post" action ="Index.php">

<label> name </label>
<input name="Name" placeholder="Type Here">


<label> email </label>
<input name="email" placeholder="Type Here">

<label> contact number </label>
<input name="Contact Number" placeholder="Type Here">

 <input id="submit" name="submit" type="submit" value="submit">


</form>
Reece
  • 89
  • 1
  • 10
  • You are mixing big letters with small letters. And instead of using if($_POST['submit']) i'd suggest you to use: if(isset($_POST['submit'])). Example: name="Contact Number", you're looking for $_POST['contact number']. Look for $_POST['Contact Number'] instead. – user2687506 Aug 07 '14 at 12:22

1 Answers1

-2

index of the post variable should be the same as the form input elements name

correct your form (with change name of elements)

<form method = "post" action ="Index.php">

<label> name </label>
<input name="name" placeholder="Type Here">


<label> email </label>
<input name="email" placeholder="Type Here">

<label> contact number </label>
<input name="contact_umber" placeholder="Type Here">

 <input id="submit" name="submit" type="submit" value="submit">


</form>

AND php

<?php
if(isset($_POST['submit']))
{
    $name = $_POST['name']; // use here the same name as in input elements of form
    $email = $_POST['email'];
    $Contact_Number = $_POST['contact_number'];
    $from='From:Client';
    $to='reece@designthink.co.uk';
    $subject='Claremont Holding Page Enquiry';
    $body = "From: $name\n E-Mail: $email\n Contact Number:\n $Contact_Number";


    if(mail($to, $subject,$body,$from))
    {
        echo '<p>Message sent!</p>';
    }
    else
    {
        echo '<p> something went wrong, please try again!</p>';
    }

}

?>
Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
  • I've done this, but now I'm getting a different error saying the mail method can't connect to the mailserver – Reece Aug 07 '14 at 12:27
  • this problem is not of the code. its you default smtp problem on server. contact to your server administrator. – Satish Sharma Aug 07 '14 at 12:28