Jump to content

Contact Us Form


Bookmark

Recommended Posts

Hi All,

 

I've only just started using forms in web design and i'm trying to create a contact us form with the options:

 

Name :-

[Form]

Email Address:-

[Form]

Comment:-

[form]

 

-----------------------------------------

 

So in the contactus.php page i have the following script:-

 

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

  Name:-<br /><input name="name" type="text" size="25"><br />

  Email:-<br /><input name="email" type"text" size="25"><br />

Message:-<br />

<textarea name="message" cols="50" rows="2"></textarea>

  <br /><input type="submit" name="submit_button" value="submit">

</form>

 

-----------------------------------------

 

But I dont understand what php coding I have to put in the file contact_form_response.php

 

-----------------------------------------

 

Thanks,

Link to comment
Share on other sites

Right, thanks for the help so far BUT, i'm getting an error somewhere.

 

--------------------------------------

file - contactus.php

 

--------------------------------------

 

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

  Name:-<br />

  <input name="name" type="text" size="25"><br />

  Email:-<br /><input name="email" type"text" size="25"><br />

Message:-<br />

<textarea name="message" cols="50" rows="2"></textarea>

  <br /><input type="submit" name="submit_button" value="submit">

</form>

--------------------------------------

 

file - contact_form_response.php

 

--------------------------------------

 

<?php

 

$name = $_POST['name'];

$email = $_POST['email'];

$message = $_POST['message'];

 

//Validation

if (3 < strlen($name) && 3 < strlen($email) && 3 < strlen($message))

{

 

$email_message = <<< EMAIL

Message from websites contact form.

 

Name: $Name

Email: $Email

 

The Message:

$message

 

EMAIL;

 

$headers ="cc:you@youralternativeaddress.com\r\n";

 

if(mail('xxxxxxxxxxxxxx@hotmail.co.uk','Contact Form email',$email_message, $headers))

{

echo "Your email has been delivered, we will contact you shortly."

}

else

{

echo "We had a problem sending the email.";

}

 

?>

 

--------------------------------------

 

The above is the code for both files, can anybody see an error in there, so when you fill out the contact us page it will send (via the submit button) to the hotmail account.

 

--------------------------------------

 

Thanks

Link to comment
Share on other sites

I usually start out with somehting simple than I build on that. try this.  I have the exact same form as you on my website and I am using this code.  Just add in the error checking. This will only send an email message to you not the person filling it out. 

<?php
$to = "you@youralternativeaddress.com";
$subject = "Contact form";
$body = "
\n\n Name: $name
\n\n E-Mail Address: $email

\n\n Message: $message";
mail ($to, $subject, $body);

header("Location: http://youralternativeaddress.com/thankyou.html"); 
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.