I have a php contact form which all works well with its validation etc, but I have one niggle with it. The original code which I have tweaked redirected the page to a new one with a thank you message on submission which I was unhappy with, so I've managed to get a thank you message to display on the original page, however the input form content still stays, i'd rather it didn't. Even better I'd like to be able to hide the form completely and replace it with a thank you.
I ought to mention that when completed it will be placed on a page with other items, so it is just the form that I'm after hiding, or clearing.
This is the code in the Header
<?php
$your_email ='email#example.com';
session_start();
$errors = '';
$name = '';
$company = '';
$visitor_email = '';
$phone = '';
$user_message = '';
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$company = $_POST['company'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
$user_message = $_POST['message'];
///------------Do Validations-------------
if(empty($name)||empty($visitor_email))
{
$errors .= "\n Name and Email are required fields. ";
}
if(IsInjected($visitor_email))
{
$errors .= "\n Bad email value!";
}
if(empty($_SESSION['6_letters_code'] ) ||
strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}
if(empty($errors))
{
//send the email
$to = $your_email;
$subject="New form submission";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "A user $name submitted the contact form:\n".
"Name: $name\n".
"Company: $company\n".
"Email: $visitor_email \n".
"Phone: $phone\n".
"Message: \n ".
"$user_message\n".
"IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body,$headers);
//header('Location: #thanks');
$myForm = '< style="visibility: hidden;">';
$thankyou = file_get_contents("thank-you.html");
}
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
And this is the form itself minus a chunk of javascript validation which I didn't think was relevant to the question
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id="footer">
<div class="twelve-column-wrapper">
<div class="six-column-wrapper">
<div class="six-column">
<h3>Why not get in touch</h3>
</div>
<div id='contact_form_errorloc' class='err'></div>
<form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<div class="three-column">
<p>
<label for='name'>Name: </label>
<br>
<input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
</p>
</div>
<div class="three-column">
<p>
<label for='company'>Your Company: </label>
<input type="text" name="company" id="company" value='<?php echo htmlentities($company) ?>'/>
</p>
</div>
<div class="three-column">
<p>
<label for='email'>Email: </label>
<br>
<input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
</p>
</div>
<div class="three-column">
<p>
<label for='phone'>Phone No. </label>
<input type="text" name="phone" id="phone" value='<?php echo htmlentities($phone) ?>'/>
</p>
</div>
<div class="six-column">
<p>
<label for='message'>Message:</label>
<br>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
</p>
</div>
<div class="three-column">
<p> <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label>
<br>
<input id="6_letters_code" name="6_letters_code" type="text">
<br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p>
<input id="submit" type="submit" value="Submit" name='submit'>
</div>
<div class="six-column"> <?php echo $thankyou; ?> </div>
</form>
</div>
</div>
</div>
I have tried a few methods I've found by searching but have fallen down mainly due to my basic knowledge of PHP.
Any help would be much appreciated.
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id="footer">
<div class="twelve-column-wrapper">
<div class="six-column-wrapper">
<div class="six-column">
<h3>Why not get in touch</h3>
</div>
<div id='contact_form_errorloc' class='err'></div>
<?php
if(!isset($_POST['submit'])):
?>
<form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<div class="three-column">
<p>
<label for='name'>Name: </label>
<br>
<input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
</p>
</div>
<div class="three-column">
<p>
<label for='company'>Your Company: </label>
<input type="text" name="company" id="company" value='<?php echo htmlentities($company) ?>'/>
</p>
</div>
<div class="three-column">
<p>
<label for='email'>Email: </label>
<br>
<input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
</p>
</div>
<div class="three-column">
<p>
<label for='phone'>Phone No. </label>
<input type="text" name="phone" id="phone" value='<?php echo htmlentities($phone) ?>'/>
</p>
</div>
<div class="six-column">
<p>
<label for='message'>Message:</label>
<br>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
</p>
</div>
<div class="three-column">
<p> <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label>
<br>
<input id="6_letters_code" name="6_letters_code" type="text">
<br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p>
<input id="submit" type="submit" value="Submit" name='submit'>
</div>
</form>
<?php
endif;
?>
<div class="six-column"> <?php echo $thankyou; ?> </div>
</div>
</div>
</div>
That will hide the form. But that won't prevent you to be spammed. If you don't want to be spammed to have to track IPs and before submitting the email check that the IP didn't already send an email let's say in the last 30 seconds, for instance.
if(empty($_POST)){
//You form goes here;
}
else{
echo $thankyou;
}
Also you can have something like:
if(empty($thankyou)){
//You form goes here;
}
else{
echo $thankyou;
}
You can trigger this function onsubmit or onclick event on form
<script>
function hideform()
{
document.forms['contact_form'].style.visibility = 'hidden';
}
</script>
You could use jQuery to clear the form div on a successful submission.
$('#myform').submit(function(){
$('#formcontainer').empty;
});
Where myform and form container are the ids of your form and the div containing your form
You better create separate action file and for display thanks message use:
if(isset($_SESSION['msg'])){
echo $_SESSION['msg'];
}
else{
//display from here
}
Related
Hi I have the same issue. Just want to print out the value that was selected on the calendar and include it to send to my email. It prints out to the page but it does not include to the email.
PHP code:
<?php
if (isset($_POST['send'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = "Attendance Form";
$date = $_POST['date[]'];
$message = "Bro./Sis. ".$name." "."attendance will be at"." ".print_r(date($date['d,m,Y']));
$emailTo = "me#domain.com";
$mailHeaders = "From: " . $name . "<". $email .">\r\n";
if (mail($emailTo, $subject, $date, $mailHeaders)) {
$message ='<div class="alert alert-success d-inline-block" role="alert">Your message has been sent.</div>';
$type = "success";
} else {
$error = '<div class="alert alert-danger d-inline-block" role="alert">Something went wrong, please try again.</div>';
}
}
?>
Hi guys thank you for your comments. I used the datepicker but whenever I use the jqueryui i cannot pick the value so i put the date as a type. This is my HTML:
<div class="container-fluid text-center" id="attendform" style="top: 50%;transform: translateY(25%) !important;position: relative;">
<!--Form for join us-->
<div class="container bg-light p-5 mt-5 d-inline-block text-center">
<h2 class="join-title text-center display-4 mb-0">Join us!</h2><br><br>
<div class="mt-0 mb-3" id="error"><? echo $error.$message; ?></div>
<div class="container text-center">
<form class="" method="post">
<label for="name" class="text-dark border-top-0 border-right-0 border-left-0" >Name: </label> <br>
<input class="form-control" type="text" name="name" id="name" placeholder="Bro./Sis."><br>
<label for="email">Email</label>
<input type="email" name="email" class="form-control" id="email" placeholder="user#domain.com" required> <br>
<!---->
<label for="date" class="d-inline-block">Date: </label>
<input type="date" id="datepicker" name="date[]" class="form-control" value=""></input><br>
<input class="btn btn-dark" id="sendbtn" type="submit" name="send" value="Send">
</form>
</div>
</div>
</div>
</div>
I disable the jquery datepicker first and try with the normal calendar
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<!--script-->
<script src="js/jquery-3.4.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js" integrity="sha256-0YPKAwZP7Mp3ALMRVB2i8GXeEndvCq3eSl/WsAl1Ryk=" crossorigin="anonymous"></script>
<!-- <script type="text/javascript">
$(function() {
$("#datepicker").datepicker();
});
</script> -->
I finally figure the answer:
PHP code
<?php
if (isset($_POST['send'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$subject = "Attendance Form";
$date = $_POST['date'];
$member = $_POST['member'];
$message = "Bro./Sis. ".$name." "."($member)"."\n\n"."Schedule:"." "."($date)";
$emailTo = "me#domain.com";
$mailHeaders = "From: " . $name . "<". $email .">\r\n";
if (mail($emailTo, $subject, $message, $mailHeaders)) {
$message ='<div class="alert alert-success d-inline-block" role="alert">Your message has been sent.</div>';
$type = "success";
} else {
$error = '<div class="alert alert-danger d-inline-block" role="alert">Something went wrong, please try again.</div>';
}
}
?>
I edited my form and put the jquery datepicker
<form class="" method="post">
<label for="name" class="text-dark border-top-0 border-right-0 border-left-0" >Name: </label> <br>
<input class="form-control" type="text" name="name" id="name" placeholder="Bro./Sis."><br>
<label for="email">Email</label>
<input type="email" name="email" class="form-control" id="email" placeholder="user#domain.com" required> <br>
<!---->
<label for="date" class="d-inline-block">Date: </label>
<input type="text" id="datepicker" name="date" class="form-control" value=""></input><br>
<p>Are you already a member of the youth?</p>
<label for=member>
<input type="radio" name="member" value="Yes member">Yes
<input type="radio" name="member" value="Non member">No
</select><br><br>
<input class="btn btn-dark" id="sendbtn" type="submit" name="send" value="Send">
</form>
I'm currently using an html5 website with a contact form and a php action to receive contact emails. I've tried a few different codes in my php but non have stopped the blank emails from coming. I do have google analytics enables on my code but have blocked the crawler through robot.txt. Here is my code.
PHP CODE
<?php
foreach ($_GET as $Field=>$Value) {
if($Value != ''){
$body .= "$Field: $Value\n";
}
}
$name = trim(htmlentities($_GET['name'],ENT_QUOTES,'utf-8'));
$email = trim(htmlentities($_GET['email'],ENT_QUOTES,'utf-8'));
$phone = trim(htmlentities($_GET['phone'],ENT_QUOTES,'utf-8'));
$messages = trim(htmlentities($_REQUEST['messages'],ENT_QUOTES,'utf-8'));
if (strlen($name) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
if (strlen($email) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
$to = "junior.8791#gmail.com";
$message = "Name: ".$name;
$message.="\n\nEmail: ".$email;
$message.="\n\nPhone: ".$phone;
$message .= "\n\nMessage: ".$messages;
$headers = "From: $email";
$headers .="\nReply-To: $email";
$success = mail($to, $subject, $message, $headers);
if ($success) {
echo "<script>window.location = 'http://www.mason372.org/thankyou.html'</script>";
} else {
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
?>
CONTACT FORM
<form action="email.php" method="post" id="form">
<div class="5grid">
<div class="row">
<div class="6u">
<input type="text" class="name" name="name" id="name" placeholder="Name" value="" aria-describedby="name-format" required aria-required=”true” pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" title="e.g.'John Doe'" required="" />
</div>
<div class="6u">
<input type="email" class="email" name="email" id="email" placeholder="Email" required="" />
</div>
</div>
<div class="row">
<div class="12u">
<input type="tel" class="tel" name="phone" id="phone" name="phone" type="text" placeholder="Phone Number" pattern="(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}" required />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="messages" id="messages" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Send Message">
<input type="reset" class="button button-alt" value="Clear Form">
i have a form with input for name and e-mail. I would like to have a dedicated error-message for each input - fx
if no name is written it will say "please write your name!"
and if the e-mail is missing or not valid it echoes "wrong mail - try again!"
At the moment I have only 1 error-message that will echo for both situations.
How can i assign an dedicated error-message for each of the inputs?
Heres the code:
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = '##gmail.com'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
<article class="kontakt">
<?php if($_POST['contactname'] != '') { //echo when a name was entered ?>
<!--<p> Hello </p>-->
<?php $name = strip_tags(trim($_POST['contactname']));
echo $name;
} ?>
</article>
<article class="kontakt">
<?php if(isset($hasError)) { // THIS PART IS ECHOED IN BOTH SITUATIONS - should only apply for error in e-mail?>
<p class="error"> Your mail is <span style="color: orange"> not correct</span> - try again! </p>
<?php } ?>
<?php if($_POST['email'] != '') { // echo when a valid mail was entered ?>
<p> Hello </p>
<?php $name = strip_tags(trim($_POST['email']));
echo $email;
} ?>
</article>
<article class="kontakt">
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<p> Your message is sent !</p>
<?php } ?>
</article>
}
?>
try something like:
if(trim($_POST['contactname']) == '') {
$hasError['contactname'] = 'Please enter a contact name!';
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError['email'] = 'Please enter email!';
} else if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError['validemail'] = 'Please enter valid email';
} else {
$email = trim($_POST['email']);
}
and this to display errors:
if(isset($hasError)){
echo '<ul>';
foreach($hasError as $error){
echo '<li>'.$error.'</li>';
}
echo '</ul>';
}
and this to keep old values upon error
<div class="right_wrap">
<div class="header"> <h5><span style="color: white"> mail </span></h5> </div>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
<article class="kontakt">
<label for="name"> Dit navn </label>
<input type="text" name="contactname" id="contactname" value="<?php echo $_POST['contactname']; ?>" class="" />
</article>
<article class="kontakt">
<label for="email"> Din mail </label>
<input type="text" name="email" id="email" value="<?php echo $_POST['email']; ?>" class="required email" />
</article>
<article class="kontakt" style="height: auto">
<label for="message"> Din besked </label>
<textarea rows="5" cols="50" name="message" class="required"><?php echo $_POST['message']; ?></textarea>
</article>
<article class="kontakt">
<input type="submit" value="Send besked" name="submit" class="button"/>
</article>
</form>
</div> <!--end of right_wrap -->
You treat each input with individual code that means you don't have much data-structure here.
Normally some kind of model for inputs as well as associated errors and values is helpful to get things done with forms.
A lightweight entry that normally works pretty well with individual PHP scripts is HTML_QuickForm2.
It does take care of individual error messages as well. You naturally can write that your own and luckily it is free software so you are allowed to study the code and learn from it.
Heres the actual form - some danish words in it. Whatever errors / messages will be output in a left wrap div - so cant be placed inside the actual form.
<div class="right_wrap">
<div class="header"> <h5><span style="color: white"> mail </span></h5> </div>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
<article class="kontakt">
<label for="name"> Dit navn </label>
<input type="text" name="contactname" id="contactname" value="" class="" />
</article>
<article class="kontakt">
<label for="email"> Din mail </label>
<input type="text" name="email" id="email" value="" class="required email" />
</article>
<article class="kontakt" style="height: auto">
<label for="message"> Din besked </label>
<textarea rows="5" cols="50" name="message" class="required"></textarea>
</article>
<article class="kontakt">
<input type="submit" value="Send besked" name="submit" class="button"/>
</article>
</form>
</div> <!--end of right_wrap -->
I have the following code for my form, and it doesn't seem to work, the query does not insert after all the fields have been filled. I'll really appreciate it if someone can look at it and help me correct any mistake. The method for the form is post and the action is <?php echo $_SERVER['PHP_SELF'];?>. This is my first code in PHP so kind of new here Thanks.
<?php
$counter=1;
if (isset($_POST["post"])) {
$gender= $_POST['gender'];
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$email= $_POST['email'];
$fone= $_POST['fone'];
$school= $_POST['skuul'];
$other= $_POST['other'];
$output_form=false;
$is_error = false;
if (empty($email)) {
echo "Please enter your email or contact info. \n";
$output_form = $is_error = true;
}
if (empty($lname)) {
echo "Please enter your email or contact info. \n";
$output_form= $is_error = true;
}
if (empty($fone)) {
echo "Please enter your email or contact info. \n";
$output_form= $is_error = true;
}
if (empty($fname)) {
echo "Please enter your name. \n";
$output_form= $is_error = true;
}
if ($output_form) {
$query= "INSERT INTO 'elect_conference' ('gender', 'fname', 'lname', 'phone', 'email', 'School', 'course', 'other')".
"values ('$gender', '$fname', '$lname', '$fone', '$email', '$school', '$course', '$other');";
$result = execute($query);
echo '<article class="extra-wrap">'."Hello $name congratulations, you are the number $counter member registered for the ELECT Conference.
A confirmation will be sent to your email ($email) within five(5) hours.\n
Thank you. And have a nice day.</artice>";
$fname="";
$lname="";
$fone="";
$email="";
$fone="";
$school="";
$subject="";
$counter++;
} else {
echo "Please ensure that all the fields are approprietly filled";}
} else {
$output_form=true;
}
if ($output_form) {
?>
<body id="page2">
<!--==============================header=================================-->
<section id="content">
<div class="pad">
<div class="main">
<article class="grid_9 suffix_1">
<div class="form1">
<div class="padding">
<h4 class="border-bot2 img-indent-bot" align="center" style="color:#00C !important">
ELECT Conference <br/>Registration
</h4>
<form id="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"enctype="multipart/form-data">
<fieldset>
<div style="margin-left:90px !important;"><?php echo "$counter/500"; ?></div>
<div class="rowElem0">
<span class="radio">Personal Infomation:</span>
<span class="radio2">
<input type="radio" name="gender" value="Mr" checked>
<label class="ratio">Mr</label>
<input type="radio" name="gender" value="Mrs">
<label class="ratio">Ms</label>
<input type="radio" name="gender" value="Mrs">
<label class="ratio">Mrs</label>
</span>
</div>
<div class="rowElem">
<label><span class="input">First Name:</span></label>
<input type="text" name="fname" value="<?php echo $fname; ?>"/>
</div>
<div class="rowElem">
<label><span class="input">Last Name:</span></label>
<input type="text" name="lname" value="<?php echo $lname; ?>"/>
</div>
<div class="rowElem">
<label><span class="input">Phone:</span></label>
<input type="text" name="fone" value="<?php echo $fone; ?>"/>
</div>
<div class="rowElem">
<label><span class="input">E-mail:</span></label>
<input type="text" name="email" value="<?php echo $email; ?>"/>
</div>
<div class="rowElem1">
<input type="radio" name="graduate" id="chbox4" checked>
<strong><label class="check2">Graduate?</label></strong>
</div>
<div class="rowElem">
<label><span class="input">School:</span></label>
<input type="text" name="skuul" value="<?php echo $school; ?>"/>
</div>
<div class="rowElem">
<label><span class="input">Course:</span></label>
<input type="text" name="course" value="<?php echo $school; ?>"/>
</div>
<div class="rowElem1">
<input type="radio" name="other" id="chbox5">
<strong><label class="check2">Other</label></strong>
<label><span class="input">Specify:</span></label>
<input type="text" name="other" value="<?php echo $other; ?>"/>
</div>
<div class="buttons">
<input class="button" type="submit" value="Submit" />
</div>
</fieldset>
</form>
</div>
</div>
</article>
</div>
</div>
</div>
</section>
<script type="text/javascript"> Cufon.now(); </script>
</body>
<?php
}
?>
</html>
Please show the form code, and be specific in the outcome of the form processing. What exactly didn't work?
In the mean time here are a couple of observations:
Instead of assigning each $_POST element at a time you can do this:
foreach ($_POST as $key=>$value) $$key = $value;
*$output_form* and *$is_error* always have the same value, why the duplication?
Okay so I am fairly new to web designing. How do I get the contact form on my current theme to work? This is the current html.
I need to know how to code the PHP file; is this correct?
<div class="form row-fluid clearfix">
<div class="field span5">
<label>Your name:</label>
<input type="text" value="" class="req" placeholder="Placeholder text..." />
</div>
<div class="field span5">
<label>Your email:</label>
<input type="email" value="" class="req" />
</div>
<div class="clearfix"> </div>
<div class="field full">
<label>Your comment:</label>
<textarea class="span12" cols="2" rows="7"></textarea>
</div>
<button class="extruded"><span>Submit</span></button>
</div>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: iclear';
$to = 'sales#tangledindesign.com';
$subject = 'Hello';
?>
And how do I link the PHP file for that contact form?
Step 1
Wrap your fields with a form HTML element that has its action property set to your php processing page
Step 2
Name the form fields according to what the php file expects
Step 3
Add some validation
Step 4
Submit and test
Example
HTML
<form action="process.php" method="post">
First Name: <input type="text" name="first_name">
<input type="submit">
</form>
PHP
<?php
$first_name=$_POST["first_name"];
if($first_name=="John")
{
echo "Hi John!";
}
else
{
echo "Sorry Buddy, Don't really know you";
}
?>
Note
The reason why i did not provide you a full solution is that you mentioned you are a newbie in that programming, and it would be injustice to just solve your problem and not guide you how to do it
You need to wrap your HTML with the tag, and don't forget to get include the submit button:
<form action="process.php" method="post">
<div class="form row-fluid clearfix">
<input type="text" name="name">
<input type="text" name="email">
<input type="text" name="message">
<input type="submit" name="submit">
</div>
</form>
Then here is the php (process.php) file to get all values from your HTML form:
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: iclear';
$to = 'sales#tangledindesign.com';
$subject = 'Hello';
Hope this help.
Try this code
<?php
$toaddress ="youremail#domain.com" //change to your email address
$error ="";
if($_SERVER['REQUEST_METHOD']=="POST") {
$name=$_POST['name'] ;
$email=$_POST['email'] ;
$comment=$_POST['comment'] ;
if(!isset($name) || $name==""){
$error .="Please Enter your name <br/>";
}elseif (!isset($email) || $email==""){
$error .="Please Enter your email Address.<br/>";
}elseif(!isset($comment) || $comment==""){
$error .="Please Enter your Comments.<br/>";
}
if ($error ==""){
mail($toaddress,"Contact form",$comment)
}
}
?>
<?php echo $error ;?>
<form method='post' action='' enctype='multipart/form-data' id='news_form' name='post_form' >
<div class="form row-fluid clearfix">
<div class="field span5">
<label>Your name:</label>
<input name="name" type="text" value="" class="req" placeholder="Placeholder text..." />
</div>
<div class="field span5">
<label>Your email:</label>
<input type="email" value="" class="req" name="email" />
</div>
<div class="clearfix"> </div>
<div class="field full">
<label>Your comment:</label>
<textarea class="span12" cols="2" rows="7" name="comment"></textarea>
</div>
<input type="submit" value="submit" />
</div>
</form>