Simple PHP form error - php

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!";
}
}
?>

Related

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>

PHP form not working

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.

Why isn't my php sending my contact form input to my email?

I am trying to write some PHP which will submit my "contact form" and send the input to a given email.
On the internet, I found the following code that does this:
<?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 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="Message sent using your contact form";
mail("vik.srk#hotmail.com", $subject, $message, $from);
echo "Email sent!";
}
}
?>
When I click submit, nothing is being sent to my inbox!
I updated your code to actually test if the mail was sent... I suspect you haven't configured an SMTP Email server, which means PHP has no way to send an email.
Your code now checks if mail() was successful.
<?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 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="Message sent using your contact form";
$MailSent = mail("vik.srk#hotmail.com", $subject, $message, $from);
if($MailSent == true) {
echo 'Mail Sent';
} else {
echo 'Mail failed';
}
}
?>
If it fails, then you know there's a problem with the mail function. You can also put error_reporting(-1) at the top to turn on errors, in case you have any syntax errors. Like I said before, I'm guessing you haven't configured a mail server which is why you aren't getting any emails.

multi-recipient PHP email form not sending emails

I'm trying to get my email form working, but something seems to be hanging up. it's not sending out emails at all!
For reference, this uses Wordpress, and this is the code:
<?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 name:<br>
<input name="username" type="text" value="" size="30"/><br>
Department:<br>
<select id="department" class="form-control-footer">
<option value="Email_0">Sales</option>
<option value="Email_1">Support</option>
<option value="Email_2">Website Feedback</option>
<option value="Email_3">Other</option>
</select><br>
Email Subject<br>
<input name="emailsubject" 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=$_POST['username'];
if (($department=="Email_0"))
{
$mailto=$_POST['example#website.com'];
}
if (($department=="Email_1"))
{
$mailto=$_POST['example#website.com'];
}
if (($department=="Email_2"))
{
$mailto=$_POST['example#website.com'];
}
else
{
$mailto=$_POST['example#website.com'];
}
$emailsubject=$_POST['emailsubject'];
$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="Webform : $emailsubject";
mail($mailto, $subject, $message, $from);
echo "Thank you for your email! Your email has been sent, and we will try to respond as soon as we can!";
}
}
?>
I've modified the base form to add in departments, which changes the recipient of the contact form. but in doing so, it seems the form no longer sends out those emails at all.
Anyone know what I've done wrong?
Here you need to add "name="department"" to the code below
<select id="department" name="department" class="form-control-footer">
Here you need to change your code as showed below:
if (($_POST['department'] == "Email_0"))
{
$mailto='example#website.com';
}
else if ($_POST['department'] == "Email_1")
{
$mailto = 'example#website.com';
}
...

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