I have two contacts forms on my website and have set up some php to send the data to a specified email address. I want to use the same php on both forms which are on different web pages. It is working on one page but not the other. I haven't used php before so am wondering if I am missing something glaring obvious, any help much appreciated. Here is my php:
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['emailaddress'];
$phone=$_POST['phone'];
$msg=$_POST['message'];
$to='example#hotmail.com';
$subject='Inquiry from website';
$message= "Name: ".$name."\n".
"Phone number: ".$phone."\n".
"Email address: ".$email."\n".
"The following inquiry has been made :"."\n\n".$msg;
if(mail($to, $subject, $message)){
echo "<h1>Message sent successfully. Thank you"." ".$name.", we will contact you as soon as possible.</h1>";
}
else{
echo "Something went wrong!";
}
}
?>
I have added my html into the post:
<form action="mail.php" method="POST">
<div class="form-group">
<input type="text" name="name" required class="form-control" placeholder="Name">
</div>
<div class="form-group">
<input type="email" name="emailaddress" class="form-control" placeholder="Email">
</div>
<div class="form-group">
<input type="text" name="phone" required class="form-control" placeholder="Phone number">
</div>
<div class="form-group">
<textarea name="message" id="message" required class="form-control" placeholder="Message"
cols="30" rows="5"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary px-5" value="Send Message">
</div>
</form>
where is your html
please send your html form
Related
I'm new to website building and was trying to get a contact form fully functional but for some reason, it's not sending any e-mails nor is it redirecting me back to the homepage. Would anyone be able to please tell me where I went wrong?
This is the HTML code:
<form action="form_contact.php" method="POST">
<div class="row">
<div class="input-group">
<input type="text" name="name" id="name" required>
<label for="name">...</label>
</div>
<div class="input-group">
<input type="text" name="number" id="number" required>
<label for="number">...</label>
</div>
</div>
<div class="input-group">
<input type="text" name="email" id="email" required>
<label for="email">...</label>
</div>
<div class="input-group">
<textarea id="message" name="message" rows="8" required></textarea>
<label for="message">...</label>
<input type="text" id="website" name="website"/>
</div>
<button type="submit" value="1" id="submit">...</button>
</form>
This is the PHP code:
<?php
if (isset($_POST['submit'])){
$nm = $_POST['name'];
$nb = $_POST['number'];
$mailFrom = $_POST['email'];
$msg = $_POST['message'];
if(!empty($_POST['website'])) die();
$mailTo='myemail#mail.com';
$headers= 'From: '.$mailFrom;
$txt= 'You have received a new e-mail from
'.$nm.'.\n\n'.$msg.'.\n\n'.$nb;
$mailSent=mail($mailTo, $txt, $headers);
if ($mailSent){
header('Location: mywebsite.com');
}}
I would greatly appreciate any help. Thank you.
I tried deleting the "website" field in the form since it's not even visible but that also didn't help.
I'm trying to create a multistep form that sends an email to me every time the form has been submitted. The form fully works except it won't send me the email. The code I used does work though for another test I did where the form is not a multistep form.
Here's the code I use:
<form <?php
error_reporting(E_ALL);
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];
$to='email#email.com'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."\n"."Email :".$email."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$message;
$headers="From: ".$email;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Sent Successfully! Thank you"." ".$name.", We will contact you shortly!</h1>";
}
else{
echo "Something went wrong!";
}
}
?> method="post" name="form" class="form-box">
<div class="step step-1 active">
<div class="form-group">
<label for="name">Name</label>
<input type="text" id="name" name="name">
</div><br>
<button type="button" class="next-btn">Next</button>
</div>
<div class="step step-2">
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email">
</div><br>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="number" id="phone" name="phone">
</div>
<button type="button" class="prev-btn">Previous</button>
<button type="button" class="next-btn">Next</button>
</div>
<div class="step step-3">
<div class="form-group">
<label for="message">Message</label>
<textarea name="message" class="message-box" placeholder="Enter Your Message Here..."></textarea>
<!-- <input type="text" id="message" name="message">-->
</div>
<button type="button" class="prev-btn">Previous</button>
<button type="submit" name="submit" value="Send" class="submit-btn">Submit</button>
</div>
</form>
Thanks in advance and I hope someone can help me figure it out.
I'm trying to create an email form using bootstrap, HTML, and PHP. I have the form here:
<form role="form-horizontal" method="post" action="formsubmit.php" style="width 70%">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="comment">Comment:</label>
<textarea class="form-control" rows="5" id="comment" name="comment"></textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Now I'm trying to code the PHP so that I receive an email with the responses. I've tried the code below yet when I receive the email its blank.
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
$message = $name . $email . $comment;
mail("someone#example.com","New contact form completion", $message )
?>
My goal is to figure out how to get an email with the responses from the form.
Try this:
$message = print_r($_POST,1);
I have gone searched the net and tried many ways of creating and validating a form which sends info to an email but I can't get my head around it. This is what I have done and it seems to work (have not been able to test if it sends), but every time I submit it comes up with "all fields required error" even with all boxes filled/empty. I looked on this site through similar questions and tried to fix it by them but no luck.
What am I missing?
Should I use the php on another page?
Once the error is fixed, will it send and keep the information submitted by the user?
In case it helps - I'm using foundation 5 for the site. Beginner at PHP.
<?php
$action=$_REQUEST['action'];
if ($action=="")
{
?>
<form action="" method="post">
<div class="row">
<div class="large-12 columns">
<input type="hidden" name="action" value="submit">
<label>Name
<input name"name" type="text" placeholder="Your name"/>
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Email
<input name"email" type="text" placeholder="Your email" />
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Your Message
<textarea name="message" type="text" placeholder="Comment here"/></textarea>
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<input id="submit" type="submit" value="Send Message">
</div>
</div>
</form>
<?php
}
else
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields required! Please fill in the form again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Hire";
mail("myemail", $subject, $message, $from);
// back to homepage - will add send confirm when fixed. header( "Location: ");
}
}
?>
Thanks in advance for any help!
You're missing = to assign value for your name attribute:
<input name="name" type="text" placeholder="Your name"/>
<!------- ^ here
and:
<input name="email" type="text" placeholder="Your email" />
<!-------- ^ and here
You are giving input attribute name for name and email like this :
<input name"name" type="text" placeholder="Your name"/>
<input name"email" type="text" placeholder="Your email" />
Change it to
<input name="name" type="text" placeholder="Your name"/>
<input name="email" type="text" placeholder="Your email" />
check this ..Add= to email and name
<input name="name" type="text" placeholder="Your name"/>
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Email
<input name="email" type="text" placeholder="Your email" />
</label>
I am having trouble setting up a PHP form. Its my first try at doing this. I have got the form to submit and send to my email. But i receive 2 emails.
Is it ment to say (unknown sender) ???? surely not.
and in this image it shows you that after only one form submit. it send one blank email, and one with text. But only the message. Whats wrong?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "adamgoredesign#gmail.com";
$subject = "New Message";
mail ($to, $subject, $message, "From: " . $name);
echo "Your Message has been sent";
?>
<form id="contactform" name="contact" method="post" action="#">
<div class="row">
<label for="name">Your Name<span class="req">*</span></label>
<input type="text" name="name" id="name" class="text" tabindex="1" placeholder="enter name" required>
</div>
<br>
<div class="row">
<label for="email">E-mail Address<span class="req">*</span></label>
<input type="email" name="email" id="email" class="text" tabindex="2" placeholder="address#domain.com" required>
</div>
<br>
<div class="row">
<label for="subject">Subject<span class="req">*</span></label>
<input type="text" name="subject" id="subject" class="text" tabindex="3" placeholder="subject title" required>
</div>
<br>
<div class="row">
<label for="message">Message<span class="req">*</span></label>
<textarea name="message" id="message" class="textarea" tabindex="4" required></textarea>
</div>
<br>
<div class="row">
<input type="submit" name="submit" value="Send Message" id="submit" />
</div>
</form>
The From header should be an email address or both a name and email address in the format:
From: John Smith <j.smith#gmail.com>
It should never be just a name, which is what you appear to be doing. Also remember to terminate headers with \r\n.
Using user input as the From header is not usually a good idea because it can introduce a header injection vulnerability, and it can also cause inconsistent spam filter results. For a contact form, I suggest just using a static email address of your own.