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>
Related
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.
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';
}
...
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!";
}
}
?>
I've this little script to send email! But it's not working... Firstly it says that my variables are not defined and then, they confirm me that the message has been sent, but it doensn't happen!
Name:
<form action="contactus.php" method="POST">
<input type="text" size="32" value="" name="name">
</form> <br><br>
E-Mail:
<form action="contactus.php" method="POST">
<input type="text" size="32" value="" name="header">
</form> <br><br>
Subject:
<form action="contactus.php" method="POST">
<input type="text" size="32" value="" name="subject">
</form> <br><br>
Message: <br>
<form action="contactus.php" method="POST">
<textarea rows="10" cols="40" name="message" value=""></textarea>
</form>
<br><br>
<form action="contactus.php" method="POST">
<input type="submit" value="Submit" name="submit">
</form>
<?php
// php script to send emails
$to = 'some#email.com';
if (isset ($_POST['message'])) {
$message = "$name" . "<br><br>" . $_POST['message'];
}
if (isset ($_POST['header'])) {
$header = "From:" . $_POST['header'];
}
if (isset ($_POST['subject'])) {
$subject = ($_POST['subject']);
}
if (isset ($_POST['name'])) {
$name = ($_POST['name']);
}
if (isset($_POST['submit'])){
mail($to, $subject, $message, $header);
echo "Your message has been sent!";
}
//end of the php script
?>
If some of you can help me would be great!
Thank you.
You can't use all those different form elements. You are using 5 separate forms and the only one that is being submitted is the one with the submit button.
Thus, when the form is being submitted there $_POST['submit'] is set, but none of the other ones exist.
So you need your HTML to be:
<form action="contactus.php" method="POST">
Name:
<input type="text" size="32" value="" name="name"><br><br>
E-Mail:
<input type="text" size="32" value="" name="header"><br><br>
Subject:
<input type="text" size="32" value="" name="subject"><br><br>
Message: <br>
<textarea rows="10" cols="40" name="message" value=""></textarea><br><br>
<input type="submit" value="Submit" name="submit">
</form>
and contactus.php:
<?php
$to = 'some#email.com';
if(isset($_POST['message']) && isset($_POST['header']) &&
isset($_POST['subject']) && isset($_POST['submit']) &&
#mail($to, $_POST['subject'], $_POST['message'], $_POST['header'])) {
echo "Your message has been sent!";
}else{
echo "There has been a problem.";
}
?>
Try:
if(mail($to, $subject, $message, $header)) {
echo "Mail sent successfully.";
} else {
echo "PHP's mail() function failed!";
}
Why you have a Form element for each input elements?
You should put all of your elements in a Form together.
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.