PHP form not working - php

I am working on a website for a real estate agency. There is one page called the details.php page, here customers can see all the characteristics of a house that they are looking for. I have a contact form on this page for a customer to fill in when he/she is interested.
If I go to www.mywebsite.com/details.php, this contact form works as it should work, I receive the email with all the contact information.
Now when a real customer uses the webpage he/she will never go to the www.mywebsite.com/details.php instead it will look like: www.mywebsite.com/properties/house-for-sale-in-London/6227.php (just an example of a property)
Here is where the contact form breaks, it shows in the URL bar all the information that was filled in like this:
www.mywebsite.com/properties/house-for-sale-in-London/6227.php?action=submit&name=TEST&telefono=TEST%40test.com&email=test%40test.com&message=Etoy+interesado+en+ver+este+inmueble.+Por+favor+contáctame.&subnewtide=Submit
but it doesn´t send, neither does it echo the thank you message.
What did I do wrong?
This is the code:
<h3>¿Quieres más información?</h3>
<form role="form" class="form-b">
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<div class="contact-form">
<form action="" id="form-anchor" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit"> Mi nombre:
<br>
<input name="name" type="text" value="" size="30" />
<br> Mi numero:
<br>
<input name="telefono" type="text" value="" size="30" />
<br> Mi correo:
<br>
<input name="email" type="text" value="" size="30" />
<br> Mensaje:
<br>
<textarea name="message" rows="3" cols="30">Estoy interesado en ver este inmueble. Por favor contáctame.</textarea>
<br>
<div class="enviar-button">
<input type="submit" class="btn btn-block btn-primary" name="subnewtide" id="subnewtide" value="Submit" />
</div>
</form>
</div>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$telefono=$_REQUEST['telefono'];
$message=$_REQUEST['message'];
$info= "Nombre: .$name. \r\n";
$info.= "Email: $email \r\n";
$info.= "telefono: $telefono \r\n";
$info.= "Codigo: $codigo \r\n";
if (($name=="")||($email=="")||($message=="")||($telefono==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("opcomercial#rentarpereira.com", $subject, $info, $message);
echo '<div class="gracias">Gracias por contactarnos, pronto un asesor atenderá tu solicitud.</div>';
}
}
?>
</form>

First of all if you're using POST method in the form parameters shouldn't be sent through the url. Now one of the issues might be the fact that you have a form nested in the form so it might take the first form element as the valid one and GET is the default method. So see if that might be the problem.

Related

PHP Form mail redirecting page not working

The form works and I get the email but when you click submit it won't take you to the thank you page, it gives me the following error message:
Error 404 - Not Found
The document you are looking for may have been removed or re-named.
Please contact the web site owner for further assistance.
This is the code for the form:
<section class="contactForm">
<h1><strong>Contact Andrea</strong></h1>
<form action="http://ddion.com/webcert_s17/andreas/DW_FINAL/formmail.php" method="post" name="form1" id="form1">
<label for="name">Name:</label>
<input name="name" type="text" required class="formStyle" id="name" form="form1">
<br>
<label for="email">Email:</label>
<input name="email" type="email" required class="formStyle" id="email" form="form1">
<br>
<label for="comments">Comments:</label>
<textarea name="comments" cols="5" required class="formStyle" id="comments" form="form1"></textarea>
<br>
<input type="submit" class="formStyle" name="submit" id="submit" value="Submit">
</form>
</section>
This is the PHP
<?php
$name=addslashes($_POST['name']);
$email=addslashes($_POST['email']);
$comments=addslashes($_POST['comments']);
// you can specify which email you want your contact form to be emailed to here
$toemail = "anlsimental#gmail.com";
$subject = "from AndreaSimentalPhotogragy.com";
$headers = "MIME-Version: 1.0\n"
."From: \"".$name."\" <".$email.">\n"
."Content-type: text/html; charset=iso-8859-1\n";
$body = "Name: ".$name."<br>\n"
."Email: ".$email."<br>\n"
."Comments:<br>\n"
.$comments;
if (!ereg("^[a-zA-Z0-9_]+#[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email))
{
echo "That is not a valid email address. Please return to the"
." previous page and try again.";
exit;
}
mail($toemail, $subject, $body, $headers);
echo "Thanks for submitting your comments";
?>
My thankyou.html is located next to the php. But somehow doesn't work... Any ideas why?
What you want to do is redirect to http://ddion.com/webcert_s17/andreas/DW_FINAL/thankyou.html instead of http://ddion.com/webcert_s17/andreas/DW_FINAL/0;URL=thankyou.html. Fix it by removing the preceding 0;URL= from the filename in the URL.
The deprecated ereg() function to preg_match()
Use this
preg_match()

how do i make my contact form work?

The code below acts strange when I click the button on my website.
First it opens a new page where the form is again displayed but without any css or js. Then when I refill all the info and click send, it says its submitted but it wont actually sent the email.
I have tried to modify the code I am still new to php.
Code below displays and functions the contact form.
<?php
$action=$_REQUEST['action'];
if ($action=="")
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Personal Plate inquiry from website";
mail("mymail#hotmail.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
There are some mistakes on your code: use $_POST instead of $_REQUEST. You can try this way:
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
if (($name =="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Personal Plate inquiry from website";
mail("mymail#hotmail.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" name="submit" value="Send email"/>
</form>

Simple PHP form error

I am trying to create a simple PHP email form that I can embed into my website. I have two problems, the syntax appears to be wrong past href=\"\"> and I am not sure why. The rest of the text appears in the browser past that href=\"\"> section. If I use this form, won't it be easier to keep users from seeing my email in this PHP form? Be advised, I am new to PHP
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("me#email.org", $subject, $message, $from);
echo "Email sent!";
}
}
?>
See anything wrong?
You are checking for $name and it doesn't exist. This will get you working but you should check if the $_REQUEST exists before you define it. Always write code with error reporting on.
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("me#email.org", $subject, $message, $from);
echo "Email sent!";
}
}
?>

Contact Form Submitting but nothing received

Hey i have a basic contact form which is submitting but nothing is being received.
I have set the form to load a template if successful, which it does.
The code below is my form code
<form name="form1" method="post" action="send_contact.php">
<input name="name" placeholder="Name" type="text" id="name" >
<input name="customer_mail" placeholder="Email" type="text" id="customer_mail">
<textarea name="detail" placeholder="Message" id="detail"></textarea>
<input type="submit" class="button" name="Submit" value="Submit">
<input type="reset" class="button" name="Submit2" value="Reset">
</form>
and this page is my submission page
<?php
//Include the common file
require_once('common.php');
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";
// Enter your email address
$to ='EMAIL ADDRESS REMOVED';
$send_contact=mail($to,$subject,$message,$header);
// If message sent..
if($send_contact){
//Display the template
$tpl->display('send-contact');
}
else {
echo "ERROR";
}
?>
I have tried sending it to and from two different email addresses and check for any filters on the email addresses themselves but i'm still unable to send my contact form.
Can anyone shed any light on this?
Thanks

PHP form action script not working

Script1 is based on CSS and html design(with some texture effect) I tried to setup php form action script to a html/css form however it keeps refreshing to the home page.. according to script if successful then it will refresh to thankyou.php, but it is not success.
However script2, I don't use any css, it is very basic html but it is working fine! but since my whole website design have css effect, I want the form also needs to have some css work.
Could someone please help me with script1? if it not possible then could you please suggest me an action script for below form, currently I don't have any action.php script, I tried few in online, unfortunately without success.
CSS form script:
<div class="row add-bottom-main">
<form name="myform" id="contactForm" action="" method="post">
<article class="span6">
<textarea id="msg" rows="3" cols="40" name="message" placeholder="Message">Message</textarea>
</article>
<article class="span6">
<input size="100" type="text" name="name" id="name" placeholder="Name">
<input type="text" size="30" id="email" name="email" placeholder="email">
<button type="submit" name="submit" id="submit" class="btn btn-renova-alt add-top-half">Send Message</button>
</article>
</form>
</div>
Script 1
<div class="row add-bottom-main">
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form name="myform" id="contactForm" action="" enctype="multipart/form-data" method="post">
<article class="span6">
<textarea id="msg" rows="3" cols="40" name="message" placeholder="Message">Message</textarea>
</article>
<article class="span6">
<input size="100" type="text" name="name" id="name" placeholder="Name">
<input type="text" size="30" id="email" name="email" placeholder="email">
<button type="submit" name="submit" id="submit" class="btn btn-renova-alt add-top-half">Send Message</button>
</article>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill again.";
}
else
{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("niranjan.thampu#gmail.com", $subject, $message, $from);
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=thankyou.php">';
exit;
}
}
?>
</div>
SCRIPT 2
<div class="row add-bottom-main">
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form name="myform" id="contactForm" action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="name" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill again.";
}
else
{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("niranjan.thampu#capital-placement.com", $subject, $message, $from);
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=thankyou.php">';
exit;
}
}
?>
</div>
Your "css form" as posted has no action set on the form and no PHP to process the page in the event that it's submitted. Your two other forms both have PHP that is testing to see if the form has been submitted and process it when it has. The PHP on those two pages is doing the work of processing the form. Without it, they would also not do anything when submit.

Categories