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);
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 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
need to add mail() to my index.php I tried and it wont work.
I have tried this a couple different ways and have read the php webpage, Idk why its not working
<div class="card p-3">
<form action="insert.php" method="post" enctype="multipart/form-data">
<div class="form-group text-center">
<h3 style="color:#5892c5;">Schedule Your Free Quote</h3>
</div>
<div class="form-group">
<label for="exampleInputName">Name<span class="required"style="color:red;"> *</span></label>
<input type="text" name="customer" class="form-control" id="exampleInputName" aria-describedby="nameHelp" placeholder="Enter First + Last Name">
</div>
<div class="form-group">
<label for="exampleInputPhone">Phone Number<span class="required"style="color:red;"> *</span></label>
<input type="phone" name="phone" class="form-control" id="exampleInputPhone" aria-describedby="phoneHelp" placeholder="Enter Mobile Phone">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputConcerns">Any Concerns?</label>
<textarea class="form-control rounded-0" name="concerns" id="exampleFormControlTextarea2" rows="3" placeholder="Message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<?php
$message = $_POST['name'] . $_POST['phone'] . $_POST['email'] . $_POST['concerns'];
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user \n".
"Here is the message:\n $message".
$to = "my_email#email.com";
mail($to,$email_subject,$email_body);
?>
</div>
Try using PHPMailer. It's easy to implement, just download the package and follow the instructions on this page: https://github.com/PHPMailer/PHPMailer
You can use PHP mail() function as following:
<?php
$to = "emailName#email.com";
$subject = "New Lead";
$message = "'$customer' '$phone' '$email' '$concerns'";
mail($to,$subject,$message);
?>
Note: you should specify the Email Address by which you want to send the message. You can specify it in php.ini file. If you're still confused, you may want to visit: https://www.w3schools.com/php/func_mail_mail.asp to know more about this function.
My goal is to make a contact form, where the user would type their name, email and message. The moment they press "Send", me, as the admin, would receive an email with all the information that was typed in before. Right now the email is sent but its empty, for example:
Reply to:
User name:
User email
User message
Also, when I click on "Send message" it gives me the same form but without CSS, there must be a code mistake which I don't know what it is.
// Form contactos.php
<div class="col-md-7 mb-5 site-animate">
<form action="index.php?cmd=contform" method="post">
<div class="form-group">
<label for="name" class="sr-only">Name</label>
<input type="text" class="form-control" id="NomeM" placeholder="Nome">
</div>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="text" class="form-control" id="EmailMen" placeholder="Email">
</div>
<div class="form-group">
<label for="message" class="sr-only">Messagem</label>
<textarea name="message" id="Mensagem" cols="30" rows="10" class="form-control" placeholder="Escreva a sua mensagem"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary btn-lg" value="Enviar Mensagem">
</div>
</form>
</div>
//File contform.php
<?php
$sql="select * from Mensagem ";
$res=$lig->query($sql);
$lin = $res->fetch_array();
$NomeM = $_POST['NomeM'];
$Email = $_POST['EmailMen'];
$Mensagem = $_POST['Mensagem'];
$email_from = 'admin03#happygreen.pt';
$email_subject = "New Form Submission";
$email_body = "User Name:" .$lin['NomeM']."\n".
"User Email:".$lin['EmailMen']."\n".
"User Message:".$lin['Mensagem']."\n";
$to = "filipajoao1933#gmail.com";
$headers = "De: $email_from \r\n";
$headers .= "Responda a: ".$lin['EmailMen']."\r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: Contactos/contactos.php");
?>
Form fields (input, select, textarea) need a name attribute you can reference in PHP, yours only have ids. Also, the for attribute in labels reference the id of a form field:
// Form contactos.php
<div class="col-md-7 mb-5 site-animate">
<form action="index.php?cmd=contform" method="post">
<div class="form-group">
<label for="NomeM" class="sr-only">Name</label>
<input type="text" class="form-control" name="NomeM" id="NomeM" placeholder="Nome">
</div>
<div class="form-group">
<label for="EmailMen" class="sr-only">Email</label>
<input type="text" class="form-control" id="EmailMen" name="EmailMen" placeholder="Email">
</div>
<div class="form-group">
<label for="Mensagem" class="sr-only">Messagem</label>
<textarea name="Mensagem" id="Mensagem" cols="30" rows="10" class="form-control" placeholder="Escreva a sua mensagem"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary btn-lg" value="Enviar Mensagem">
</div>
</form>
</div>
And your $email_body should be:
$email_body = "User Name:" .$NomeM."\n".
"User Email:".$EmailMen."\n".
"User Message:".$Mensagem."\n";
I've been working on a contact form. I have added used the POST method to send it to a set email address. It doesn't seem to be working though. It just runs and stops as if the code is broken. The HTML and PHP are below.
<form action="contact-form.php" method="post" id="contact-form" name="contact-form">
<div class="form-group">
<label for="name">Your name</label> <input class=
"form-control" id="name" name="name" type="text">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input class="form-control" id="email" name="email"
type="email">
</div>
<div class="form-group">
<label for="phone">Phone</label> <input class=
"form-control" id="phone" name="phone" type="text">
</div>
<div class="form-group">
<label for="message">Your message</label>
<textarea class="form-control" id="message" name=
"message" rows="6">
</textarea>
</div>
<div class="submit">
<input class="button button-small" type="submit"
value="Send">
</div>
</form>
<?php
if(isset($_POST['submit'])) {
$to = "gfrazer#hotmail.co.uk";
$from = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$message = $name . " " . " wrote the following: " . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
header('Location: http://www.google.co.uk');
}
?>
You need to add a name to your submit button. From your snippit, you have no $_POST['submit']:
<form action="contact-form.php" method="post" id="contact-form" name="contact-form">
<div class="form-group">
<label for="email">Email address</label>
<input class="form-control" id="email" name="email" type="email">
</div>
<div class="form-group">
<label for="phone">Phone</label> <input class="form-control" id="phone" name="phone" type="text">
</div>
<div class="form-group">
<label for="message">Your message</label>
<textarea class="form-control" id="message" name="message" rows="6"></textarea>
</div>
<div class="submit">
<!-- ADD name="submit" -->
<input name="submit" class="button button-small" type="submit" value="Send" />
</div>
</form>