So i've got this assignment at school to make a web page to a company.
I have been using desingmodo's slides template. There is a guide to make a working form but mine isn't sending the email to specified address, but i do get the "success" message after submitting.
send_mail.php
<?php
$toEmail = "example#gmail.com"; ***i have the correct email here on my .php***
$mailHeaders = "From: ".$_POST["userName"]." <". $_POST["userEmail"] .">\r\n";
$message_content = "Subject: Contact Form Message\r\n
From: ".$_POST["userName"]." ".$_POST["userEmail"]."\r\n
Message: ".$_POST["content"]."";
if(mail($toEmail, 'Contact Form Message', $message_content, $mailHeaders)) {
print "<p class='success'>Message Sent. Thank You!</p>";
} else {
print "<p class='Error'>Problem in Sending Mail.</p>";
}
?>
HTML form
<form class="wide center" action="send_mail.php" id="contact-form" method="post" novalidate="novalidate">
<label class="uppercase ae-4" for="name37">Your name</label>
<input class="stroke round ae-5 wide" id="name" name="name" type="text" placeholder="Name" required/>
<span id="userName-info" class="info"></span>
<label class="uppercase ae-6" for="email37">Email</label>
<input class="stroke round ae-7 wide" id="email" type="email" name="email" placeholder="Email" required/>
<span id="userEmail-info" class="info"></span>
<label class="uppercase ae-8" for="message37">Message</label>
<textarea class="stroke round left ae-9 sourceSans" id="message37" name="message" placeholder="Message" required></textarea>
<span id="content-info" class="info"></span>
<input class="button wide pink round uppercase ae-10 button-55 done" type="submit" name="submit" value="Send message">
im assuming the val_submit.js isnt causing any problems since im getting the "message sent" page.
Any ideas what im missing?
Replace your form with this it will run
Check with name you used in php should be same in form input names
<form class="wide center" action="send_mail.php" id="contact-form" method="post" novalidate="novalidate">
<label class="uppercase ae-4" for="name37">Your name</label>
<input class="stroke round ae-5 wide" id="name" name="userName" type="text" placeholder="Name" required/>
<span id="userName-info" class="info"></span>
<label class="uppercase ae-6" for="email37">Email</label>
<input class="stroke round ae-7 wide" id="email" type="email" name="userEmail" placeholder="Email" required/>
<span id="userEmail-info" class="info"></span>
<label class="uppercase ae-8" for="message37">Message</label>
<textarea class="stroke round left ae-9 sourceSans" id="message37" name="content" placeholder="Message" required></textarea>
<span id="content-info" class="info"></span>
<input class="button wide pink round uppercase ae-10 button-55 done" type="submit" name="submit" value="Send message">
Related
I am using PHPMailer to send email from my Gmail account to an email from a submitted form on my index.html page. This works perfectly fine. But since I am using the send.php file in the action attribute, the send.php page appears after form submission. I want to stay on the index.html page and let send.php work in the background and alert on the index.html page, when the email is sent.
Note: There isn't any SQL or any database job here. I am using PHPMailer in send.php to send an email from my Gmail account to the user submitted Gmail id in the form.
<form action="send.php" class="form" id="frm-js" method="POST">
<div class="form__group">
<input type="text" class="form__input" id="name" name="name" placeholder="Full Name" required>
<label for="name" class="form__label">Full Name</label>
</div>
<div class="form__group">
<input type="text" class="form__input" id="email" name="email" placeholder="Email Address" required>
<label for="email" class="form__label">Email Address</label>
</div>
<div class="form__group">
<input type="text" class="form__input" id="phone" name="phone" placeholder="Phone Number">
<label for="phone" class="form__label">Phone Number</label>
</div>
<div class="form__group">
<textarea id="message" rows="4" cols="50" name="message" class="textarea-frm form__input" maxlength="1000" placeholder="Your message"></textarea>
</div>
<div class="form__group">
<button class="btn" type="submit" name="submit">Book</button>
</div>
</form>
You can use jQuery. Try this: remove action from the form tag. I add a p to show the message from send.php:
<form class="form" id="frm-js" method="POST">
<p id="resp_msg"></p>
<div class="form__group">
<input type="text" class="form__input" id="name" name="name" placeholder="Full Name" required>
<label for="name" class="form__label">Full Name</label>
</div>
<div class="form__group">
<input type="text" class="form__input" id="email" name="email" placeholder="Email Address" required>
<label for="email" class="form__label">Email Address</label>
</div>
<div class="form__group">
<input type="text" class="form__input" id="phone" name="phone" placeholder="Phone Number">
<label for="phone" class="form__label">Phone Number</label>
</div>
<div class="form__group">
<textarea id="message" rows="4" cols="50" name="message" class="textarea-frm form__input" maxlength="1000" placeholder="Your message"></textarea>
</div>
<div class="form__group">
<button class="btn" type="submit" name="submit">Book</button>
</div>
</form>
And add a jQuery function (integrate jQuery if you haven't already library):
$("#frm-js").on("submit", function(event){
event.preventDefault();
var data = $( this ).serialize();
$.post("send.php",{data:data }, function (data) {
// Do other stuff like
// reset form items
// Show message response
$("#resp_msg").text(data).show();
});
});
This is send.php and is how it should be:
if(isset($_POST['data'])) {
$params = array();
parse_str($_POST['data'], $params);
// Send mail
echo "Hi, " . $params['name'] . " your email has been sent";
}
The email I receive only shows the message, not the email address or phone number or even the name.
It also doesn't show from which email it has been sent.
I should receive whole information from the form, otherwise it wouldn't show me the message, I guess.
Maybe someone has more simple code than this one?
I tried but I'm stuck.
Can someone help me out?
Below is the HTML and PHP code
HTML Code:
<form name="mail" action="mail.php" method="post" >
<div class="form-group ">
<input id="name" class="form-control" placeholder="Name" type="text" required>
<label for="name" class="sr-only">Name</label>
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input id="email" class="form-control" placeholder="Email" type="email" required>
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Phone</label>
<input id="phone" class="form-control" placeholder="Phone" type="text" required>
</div>
<div class="form-group ">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" cols="30" rows="5" class="form-control" placeholder="Message" required></textarea>
</div>
<div class="form-group ">
<input class="btn btn-primary btn-lg" value="Send Message" name="submit" type="submit">
</div>
</div>
</form>
PHP code:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$email_from = "$email";//<== update the email address
$email_subject = "New Form submission";
$email_phone = $phone;
$email_body = "You have received a new message from the user ".$name.
"\nHere is the message:\n ".$message.
"\nThe phone number:\n ".$phone.
"The email:\n ".$email.
$to = "info#czwebdesign.be";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: index.html');
?>
You also need to use name attribute for other fields as well same like message field, something like:
<input name="email" class="form-control" placeholder="Email" required>
<input name="name" class="form-control" placeholder="NAme" required>
<input name="phone" class="form-control" placeholder="Phone" required>
Otherwise you will get the Undefined Index warning in your script.
It's better to use php error_reporting() in your development mode, this will help to find out all errors and warnings in your code.
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
Try this
<form name="mail" action="mail.php" method="post" >
<div class="form-group ">
<input id="name" class="form-control" placeholder="Name" type="text" name="name" required>
<label for="name" class="sr-only">Name</label>
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input id="email" name="email" class="form-control" placeholder="Email" type="email" required>
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Phone</label>
<input id="phone" name="phone" class="form-control" placeholder="Phone" type="text" required>
</div>
<div class="form-group ">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" cols="30" rows="5" class="form-control" placeholder="Message" required></textarea>
</div>
<div class="form-group ">
<input class="btn btn-primary btn-lg" value="Send Message" name="submit" type="submit">
</div>
</div>
</form>
Look here at the missing name="" attribute in your <input>
Use this code instead:
<form name="mail" action="mail.php" method="post" >
<div class="form-group ">
<input name="name" id="name" class="form-control" placeholder="Name" type="text" required>
<label for="name" class="sr-only">Name</label>
</div>
<div class="form-group ">
<label for="email" class="sr-only">Email</label>
<input name="email" id="email" class="form-control" placeholder="Email" type="email" required>
</div>
<div class="form-group ">
<label for="phone" class="sr-only">Phone</label>
<input name="phone" id="phone" class="form-control" placeholder="Phone" type="text" required>
</div>
<div class="form-group ">
<label for="message" class="sr-only">Message</label>
<textarea name="message" id="message" cols="30" rows="5" class="form-control" placeholder="Message" required></textarea>
</div>
<div class="form-group ">
<input class="btn btn-primary btn-lg" value="Send Message" name="submit" type="submit">
</div>
</div>
</form>
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>
I am a beginner and I am trying to use this tutoriel http://untame.net/2013/05/how-to-build-a-modal-contact-form-in-twitter-bootstrap-with-php-ajax for creating my contact form. Email not sending ! Do you have an idea, why ? Thanks for your help !
After clicking on Send I have this on adresse web : http://viktorius.fr/?question=&email=&save=contact
Here the HTML code :
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_012_heart.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
</div>
<h5 id="Email" align="left" color="#000"<span style="color:black">For the answer, let us your email :</h5>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_290_skull.png"></span></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="Email">
</div>
<!-- Form itself -->
<div class="form-actions">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-primary pull-right">Send</button><br />
Here the PHP code :
<?php
ini_set(“SMTP”,”smtp.viktorius.fr”);
ini_set(“smtp_port”,”25″);
$myemail = 'postmaster#viktorius.fr';
if (isset($_POST['question'])) {
$email = strip_tags($_POST['email']);
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks! Here is what you submitted:</span><br><br>";
echo "<stong>Question:</strong> ".$question."<br>";
echo "<stong>Email:</strong> ".$email."<br>";
if (isset($_POST['name']))
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
Check the name of your inputs, php cant read your post data.
There is not a single form here...
the ajax expects to serialize
<form class="contact">...
$('form.contact').serialize(),
And you don't have a form
You should put all your inputs and button inside a form tag with class contact like this:
<form action="" class="contact">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_012_heart.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" placeholder="What is your question ?">
</div>
<div style="margin-bottom: 25px;" class="input-group">
<span class="input-group-addon"><img src="img/glyphicons_290_skull.png"></span>
<input id="login-username" type="text" class="form-control" name="username" value="" color="#000000"placeholder="For the answer, let us your email adress here :">
</div>
<div class="form-actions">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-primary pull-right">Send</button><br>
</div>
</form>
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>