Hi Can anyone suggest a quick form script for a php form?
I generated the one below from telepro and modified the html and emails a bit, but I get this error for the checkbox
Parse error: syntax error, unexpected '=' in /home/inn.co.uk/public/mailer.php on line 14
thanks for your help
Regards
Judi
<form method="POST" action="contact.php">
<div class="form-field">
<input type="text" name="Name" onFocus="if(this.value=='Name')this.value='';" value="Name">
</div>
<div class="form-field">
<input type="text" name="Telephone" onFocus="if(this.value=='Telephone')this.value='';" value="Telephone">
</div>
<div class="form-field">
<input type="text" name="Timetocall" onFocus="if(this.value=='Time to call')this.value='';" value="Time to call">
</div>
<div class="form-field">
<ul class="tickboxes">
<li>Do you agree to our<br/>Terms of Business <input type="checkbox" name="DoyouagreetoourTermsofBusiness?" value="Yes" /></li></ul></div>
<div class="button">
<input type="image" src="images/submit.jpg" value="" name="submit">
</div>
</form>
<?php
// Website Contact Form Generator
// http://www.tele-pro.co.uk/scripts/contact_form/
// This script is free to use as long as you
// retain the credit link
// get posted data into local variables
$EmailFrom = "enquiry#inn.co.uk";
$EmailTo = "judith#yahoo.co.uk";
$Subject = "New enquiry";
$Name = Trim(stripslashes($_POST['Name']));
$Telephone = Trim(stripslashes($_POST['Telephone']));
$Timetocall = Trim(stripslashes($_POST['Timetocall']));
$DoyouagreetoourTermsofBusiness? = Trim(stripslashes($_POST['DoyouagreetoourTermsofBusiness?']));
// validation
$validationOK=true;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Telephone)=="") $validationOK=false;
if (Trim($Timetocall)=="") $validationOK=false;
if (Trim($DoyouagreetoourTermsofBusiness?)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "Timetocall: ";
$Body .= $Timetocall;
$Body .= "\n";
$Body .= "DoyouagreetoourTermsofBusiness?: ";
$Body .= $DoyouagreetoourTermsofBusiness?;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
You are using a question mark in your variable name. That doesn't work.
See the PHP Manual on variables for naming conventions.
replace
$DoyouagreetoourTermsofBusiness?
by
$DoyouagreetoourTermsofBusiness
and it will work fine.
Related
whats wrong in my code?
In HTML, I have taken form and i have created heading3 and i taken two inputs for name and email and i written textarea for message at last i taken another input is for submit and i closed the form tag.
<form method="post" action="contactengine.php">
<h3>Message Me</h3>
<input type="text" name="Name" id="Name" placeholder="Enter Name" required>
<input type="email" name="Email" id="Email" placeholder="Enter Email" required>
<textarea name="Message" id="Message" placeholder="Your Message"> </textarea>
<input type="submit" name="submit" value="Send Now" class="submit-button">
</form>
<?php
$EmailFrom = "xyz#gmail.com"; //your first email from where you want to send email
$EmailTo = "abc#gmail.com"; //your second email where you want to receive contact form content
$Subject = $_POST['Name']." Contacted you from your portfolio site"; //mail subject
$Name = Trim(stripslashes($_POST['Name'])); //getting name from html page
$Email = Trim(stripslashes($_POST['Email'])); //getting email from html page
$Message = Trim(stripslashes($_POST['Message'])); //getting message from html page
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
I would try this:
// send email
$success = mail($EmailTo, $Subject, $Body, "From:" . $EmailFrom);
I'm trying to make a simple contact form. However, when the email comes through all the responses are blank.
<?php
$EmailFrom = "hideemail";
$EmailTo = "hideemail";
$Subject = "GrueRadio - Form Submission";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=thank-you-form.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
<form style="padding-top: 70px;" method="post" action="engine.php">
<h1 style="color: #442154;text-align: center;"><strong>Contact</strong></h1>
<p class="faq-para" style="padding-bottom: 20px;text-align: center;">Need to contact the team about a DCMA, Song Request or another issue?<br>You can also contact us directly, dan#gruegamers.com.</p>
<div class="form-group"><input class="form-control form-control-lg" type="text" style="width: 50%;margin-left: 25%;" required="" placeholder="Name" name="name"></div>
<div class="form-group"><input class="form-control form-control-lg" type="email" style="width: 50%;margin-left: 25%;" placeholder="Email" name="email"></div>
<div class="form-group"><textarea class="form-control form-control-lg" style="width: 50%;margin-left: 25%;min-height: 200px;" placeholder="What are you contacting us about? Please specify with much information as possible." name="message"></textarea></div>
<div class="form-group"><button class="btn btn-dark btn-lg" style="width: 50%;margin-left: 25%;" type="submit">Submit form</button></div>
</form>
Would appreciate any pointers to get this working. This is what I have tried so far.
Thanks
Because $_POST['key'] is case sensitive and you put capital letter on your PHP code. Your keys should match exactly with your input names.
This question already has answers here:
How to read if a checkbox is checked in PHP?
(21 answers)
Closed 5 years ago.
I have a working form but I would like to add a check box to it. Sorry, completely new to PHP so I'm unsure what I would need to add to the PHP to make it work.
The HTML:
<label for="Name"></label>
<input type="text" placeholder="Name" name="Name" id="Name" />
<label for="Tel"></label>
<input type="text" placeholder="Tel" name="Tel" id="Tel" />
<label for="Email"></label>
<input type="text" name="Email" placeholder="Email address" id="Email" />
<label for="Message"></label><br />
<textarea name="Message" placeholder="Your Message" rows="10" cols="20" id="Message"></textarea>
<label for="Subscribe"></label>
<input type="checkBox" name="CheckBox" id="checkbox" /> <p>Please tick this box to be kept up to date with offers</p>
The PHP:
$EmailFrom = "me#test.com";
$EmailTo = "me#test.com";
$Subject = "Enquiry from website";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
$Message = Trim(stripslashes($_POST['Checkbox']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=https://myurl.com\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
Any help would be really appreciated. Thanks
You're overwriting the $Message var with the value of the checkbox:
$Message = Trim(stripslashes($_POST['Message']));
$Message = Trim(stripslashes($_POST['Checkbox']));
You could also consider that checkboxes send on/off values unless you specify a different value with the parameter value="xxxx"
I'm trying to create a form where the user is required to use a password that I give them.
So when the user submits a form they will have to type "Password123" into the form before they can submit the form to my email. However, if they get the password wrong, the site will redirect to an error page.
So far, I keep getting an internal server error.
Here is the html:
<form method="post" action="contactengine.php">
<div class="forms">
<h4>PASWORD: <input type="password" placeholder="******" name="Password" /></h4>
<h4>YOUR NAME: <input type="text" placeholder="Smith Family" name="Name" /></h4>
<h4>YOUR CITY: <input type="text" placeholder="Anytown, USA"name="City" /></h4>
<h4>YOUR TELLEPHONE: <input type="text" placeholder="123.456.7891"name="Tel" /></h4>
<h4>YOUR EMAIL: <input type="text" placeholder="you#emaildomain.com" name="Email" /></h4>
<h4>MESSAGE TO US:</h4> <textarea width="10000px" name="Message" placeholder="Go ahead and say something nice to us!" rows="20" cols="20" id="Message"></textarea>
<br>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
</div>
This is the PHP:
<?php
$Password = Trim(stripslashes($_POST['Password']));
$EmailFrom = "me#gmail.com";
$EmailTo = "me#gmail.com";
$Subject = "THIS IS THE SUBJECT";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// THIS IS WHERE I AM STUCK
if ($Password != "Password123") {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
May be you can try this ...
if ($Password != "Password123") {
echo "<script language='javascript'> window.location='error.htm'; </script>";
exit;
}
if ($Password != "Password123") {
echo "<script>document.location.href='new.php'</script>";
}
You may try this code,May be helpful to you.
I've got a simple contact form set up, but am having a little trouble with the finishing touches. I'm getting an error message whenever the form is submitted. Was hoping someone can take a look at my code and point out my mistake. Thanks!
(edited) Forgot to mention the error is that once form is submitted, I am being redirected to the error page (error.html) instead of the success (contactthanks.php) page.
HTML:
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="City">City:</label>
<input type="text" name="City" id="City" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
PHP:
<?php
$EmailFrom = "";
$EmailTo = "MYEMAIL#gmail.com";
$Subject = "";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
exit;
}
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
It is redirecting to your error page because the call to mail is returning false (indicating the email was not accepted for delivery) and that is exactly what you are telling it to do in that situation.
You need to check the SMTP set up on your server.
Typically the settings to check for are sendmail_from and sendmail_path in your PHP.ini file. Seeing as you are already setting a From header, sendmail_path is likely to not be set up correctly.
See what's causing the problem with
ini_set("display_errors", "1");
error_reporting(E_ALL);`.
My guess is you have wrong smtp settings and mail function fails.