Form
<form method="post" action="php/contactengine.php">
<ul>
<li><label for="Name">Name:</label></li>
<li><input type="text" name="Name" id="Name" /></li>
</ul>
<ul id="Surname">
<li><label for="Surname">Surname:</label></li>
<li><input type="text" name="Surname" id="Surname" /></li>
</ul>
<ul>
<li><label for="Town">Town:</label></li>
<li><input type="text" name="Town" id="Town" /></li>
</ul>
<ul>
<li><label for="Tel">Mob/Tel:</label></li>
<li><input type="text" name="Tel" id="Tel" /></li>
</ul>
<ul>
<li><label for="Email">Email:</label></li>
<li><input type="text" name="Email" id="Email" /></li>
</ul>
<ul>
<li><label for="Message">Message:</label><br /></li>
<li><textarea name="Message" rows="30" cols="20" id="Message"></textarea></li>
</ul>
<input type="submit" name="submit" value="Submit" class="submit-button" />
<input type="reset" name="reset" value="Clear" class="reset-button" /></form>
Engine
<?php
$EmailFrom = "enquiry#madisonjacob.co.uk";
$EmailTo = "james#madisonjacob.co.uk";
$Subject = "Website communication - MadisonJacob";
$Name = Trim(stripslashes($_POST['Name']));
$Surname = Trim(stripslashes($_POST['Surame']));
$Town = Trim(stripslashes($_POST['Town']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-error.php\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Town: ";
$Body .= $Town;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
if(isset($_POST['Surame']) && $_POST['Surname'] == '') {
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
}
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-thanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-error.php\">";
}
?>
...
Having issues with the contact form just going to the error page without any css showing. Think I've broken it somewhere too using some suggestions (my fault i'm sure).
Do I have to force a refresh on initial load with a counter so that it doesn't keep on reloading (if so how is best to do this please)?
If it's just that I'm not using the best code above then please correct me thanks.
Surname is a hidden field (hidden by css) to stop bots using the form.
All help much appreciated.
Could you please post your full code? Rest i feel you must use
document.location.href = 'contact-thanks.php';
for redirection.
Related
I made a form where you could fill out some details and when you clicked "send" it sent to your email, It worked fine for me but people told me they clicked send but i didn't see anything in my inbox, I hope someone got a solution, Thanks
<form action="MAILTO:myemail#gmail.com?subject= Intro request" method="post" enctype="text/plain">
Just use PHP to send email:
HTML form for email input:
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<input type="text" name="name" class="form-control" required="required" placeholder="Name">
<input type="email" name="email" class="form-control" required="required" placeholder="Email address">
<textarea name="message" id="message" required="required" class="form- control" rows="8" placeholder="Message"></textarea>
<button type="submit" id="submit" class="btn btn-danger btn-lg">Send Message</button>
</form>
When the submit button is clicked, the form will be sent to the server to be processed by php script below.
sendEmail.php:
$name = $_POST['name'];
$email = $_POST['email'];
$subject = 'query';
$message = $_POST['message'];
$email_from = $email;
$email_to = 'myemail#gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = mail($email_to, $subject, $body, 'From: visitor');
Hope this helps
Some website's search boxes aren't very good: when you put a space in the search bar and submit, it returns every search item they have. (Example: http://watchfreemovies.unblocked.co/)
Mine does the same. What can I do to make it verify that there is actual text in the search box before submitting?
Search box and button:
<div class="Nava">
<input type="button" name="button" id="hello" value="M" />
</div>
<form action='/search.php' method='GET'>
<input id='searchbar' type='text' name='search' placeholder="search for movies & shows" maxlength="50" />
<input id='submit' type='submit' name='submit' value='Search' />
</form>
<div class="Navbuttons">
<input type="button" name="button" id="button" value="shows" />
<input type="button" name="button" id="button" value="movies" />
</div>
Results page:
$x = 0;
$construct = '';
$search = $_GET['search'];
$search = preg_replace("#[^0-9a-z ]#i", "", $search);
if (strlen($search) <= 0)
echo "Search term too short";
else {
echo "You searched for '<b>$search</b>' ";
mysql_connect("localhost", "root", "");
mysql_select_db("search");
$search_exploded = explode(" ", $search);
foreach ($search_exploded as $search_each) {
$x++;
if ($x == 1)
$construct .= "keywords LIKE '%$search_each%'";
else
$construct .= "AND keywords LIKE '%$search_each%'";
}
$construct = "SELECT * FROM searchengine WHERE $construct";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
if ($foundnum == 0)
echo "<p>Sorry, there are no matching result for '<b>$search</b>'.</p>
<li> Try different words with similar
meaning</li>
<li> make sure you're spelling is correct</li>";
else {
echo "$foundnum results found !";
while ($runrows = mysql_fetch_assoc($run)) {
$title = $runrows['title'];
$desc = $runrows['description'];
$url = $runrows['url'];
echo "
<hr><a href='$url'><h2><b>$title</b></h2></a><br>
$desc<br>
<a href='$url'></a><p>
";
}
}
}
Check server-side:
if (!trim($_GET['search'])) {
echo 'Enter a query.';
}
Check client-side:
<form action='/search.php' method='GET'>
<input id='searchbar' type='text' name='search' placeholder="search for movies & shows" maxlength="50" required />
<input id='submit' type='submit' name='submit' value='Search' disabled />
</form>
<script>
document.getElementById('searchbar').onkeypress = function() {
document.getElementById('submit').disabled = !this.value.trim();
}
</script>
Fiddle
I'm using the following HTML:
<div>
<form method="post" action="mailto:hr#kine.com" >
<input type="submit" value="Send Email" />
</form>
</div>
However, when I try and load the page, I get the following error:
No webpage was found for the web address
Why does this happen, and how can I fix this?
Try below code to send email using php & html
<div>
<form method="post">
<input type="submit" name='submit' value="Send Email" />
</form>
</div>
<?php
if(isset($POST['submit']){
$to = 'hr#kine.com';
$subject = 'Website Change Reqest';
$headers = "From: test#example.com\r\n";
$headers .= "Reply-To: test#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = 'Test Email';
$message .= '<h1>Hello, World!</h1>';
mail($to, $subject, $message, $headers);
}
?>
I hope it can help you.
contact-form.html
<form method="POST" name="contactform" action="contact-form-handler.php">
<p>
<label for='name'>Your Name:</label> <br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label> <br>
<input type="text" name="email"> <br>
</p>
<p>
<label for='message'>Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit"><br>
</form>
contact-form-handler.php
<?php
$errors = '';
$myemail = 'net.dev#spikyarc.net';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
This both file i have put in wwwroot folder but when i submit html form it gives error The page cannot be displayed. I cannot find problem. Thanks for helping me.
set the action in the HTML form to:
contact-form-handler.php
like:
<form method="POST" name="contactform" action="contact-form-handler.php">
UPDATE 1: And check this:
Change
$email_subject = "Contact form submission: $name";
to
$email_subject = "Contact form submission:" . $name;
UPDATE 2: And this also:
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
to:
$headers = "From: " . $myemail . "\n";
$headers .= "Reply-To:" . $email_address;
UPDATE 3:
You validate the E-mail address $email_address but never use it.
Be sure to check the filename with that in the action!!
When I submit my form an email is sent to my email address with details entered in the form but when I recieve the email the data is blank here is my code
<?php
$form = '<form action="test2.php" method="POST">
<table width="300" style="border: 1px solid black;">
<tr>
<td>Name <td><input type="text" id="name">
<tr>
<td>Phone Number <td><input type="text" id="telephone">
<tr>
<td colspan="2">
<input type="submit" name="submit" value="submit"/></div>
</tr>
</table>';
echo $form;
$to = 'redacted#redacted.redacted';
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$body = "<div>Name: $name <br>Telephone Number: $telephone<br></div>";
// subject
$subject = 'Call Back Requested';
// message
$message = $body;
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:' . "\r\n";
$headers .= 'From: Call Back Request <contact-us-form#yellowgrid.co.uk>' . "\r\n";
if(isset($_POST['submit'])){
mail($to, $subject, $message, $headers);
}
?>
The problem is when I submit the form the I recieve an email that says
Name (Nothing)
Phone Number (Nothing)
Can anyone tell me where I am going wrong
Thanks In Advance
Adam
You have to specify the name attribute for your inputs:
<input type="text" id="name" name="name">
<input type="text" id="telephone" name="telephone">
instead of
<input type="text" id="name">
<input type="text" id="telephone">
Just after a quick look you should swap your $body to read
$body = '<div>Name: ' . $name . '<br>Telephone Number: ' . $telephone . '<br></div>';
Try that out and see if it works
you have alot of mistakes in closing tags .. and its bad practice to display a whole html form using echo .. check out this code:
<?php
extract($_POST);
if ( isset($submit) )
{
$to = 'adam.albison#yellowgrid.co.uk';
$body = "<div>Name: $name <br>Telephone Number: $telephone<br></div>";
$subject = 'Call Back Requested';
$message = $body;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To:' . "\r\n";
$headers .= 'From: Call Back Request <contact-us-form#yellowgrid.co.uk>' . "\r\n";
mail($to, $subject, $message, $headers);
}
?>
<html>
<form action="test2.php" method="POST">
<table width="300" style="border: 1px solid black;">
<tr>
<td>Name </td>
<td> <input type="text" id="name" name="name" /> </td>
</tr>
<tr>
<td>Phone Number </td>
<td> <input type="text" id="telephone" name="telephone" /> </td>
</tr>
<tr>
<td colspan="2"> <input type="submit" name="submit" value="submit"/> </td>
</tr>
</form>
</html>