Jump to content

Need help with contact form


Ajith

Recommended Posts

Hello,

 

I need a contact form with fields:

 

Name:

Email:

Phone:

Message:

 

I have html contact form but when a visitor clicks on submit button then a pop up says thnq for contacting us and he need to be on the same page. the details has to get in mail to me.

Link to comment
Share on other sites


<form action="" method="post" name="contact">
<input type="text" name="name" placeholder="First and Last Name" /><br />
<input type="email" name="email" placeholder="Email Address" /><br />
<input type="text" name="phone" placeholder="Phone Number" /><br />
<textarea name="message">
Type Your Message Here
</textarea><br />
<input type="submit" name="submit" value="Send" /><br />
</form>

<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];

$to = 'Your Email Address';
$subject = 'Contact Message From - ' . $name;
$body = "Name: {$name}\n
Email: {$email}\n
Phone: {$phone}\n
Message:\n
{$message}";

mail($to, $subject, $body);

}
Link to comment
Share on other sites

Note, though the code above from chriscloyd should work as a contact form that sends you an email - you MUST apply some form of security to the data posted by the user otherwise you'll swiftly find your database corrupted or your contact form becomes used for sending spam mail. ALWAYS, always validate the user somehow - even if its just one of those annoying captchas.

 

Good luck.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Ensure you have set the correct email address in the $to variable. It's difficult to know what your issue is unless you post your current code though.


 


http://php.net/manual/en/function.mail.php


 


http://email.about.com/od/emailprogrammingtips/qt/How_to_Send_Email_from_a_PHP_Script.htm


 


http://www.w3schools.com/php/func_mail_mail.asp


 


Every one of the above pages explains how to use the mail() function. I advise care regards security once more.


 


'Popups' are achievable by several means - again, a short trawl through the first page of results from your favourite search-engine will provide you with examples on how to achieve this. However, it would be worth bearing in mind from a UX point of view, that the method of displaying an item the user has to dismiss before they can access the page's content, should be used only at apposite times. i.e. if a user is about to delete something that will be irretrievable. Why can't you just show the 'Thank You' on the page in a highly visible manner?


 


Anyway, it's not for me to dictate your strategy, I merely offer information. If you do continue the 'popup' route, you might consider jQuery or some other javascript library.


 


Good luck.


Edited by wezhind
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.