Ok I need to make this contact form highlight red and say not valid inside the boxes! What ever I do I can't get it to work! I can't change the HTML tags that are already there you can add to the HTML but not delete any of it but I want it to display on the same page with JavaScript and have it look very nice can someone edit what I have and help me make this work please!
Oh and I keep getting 2 emails every time I test it also!
Here is there HTML:
<!-- Contact -->
<div class="wrapper wrapper-style4">
<article id="contact">
<header>
<h2>Want to hire me? Get in touch!</h2>
<span>I do quality work and would love to work for you!.</span>
</header>
<div>
<div class="row">
<div class="12u">
<div id="errors"></div>
<form method='post' action='mailform.php' id='contact-form'>
<div>
<div class="row half">
<div class="6u">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" name="email" id="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<input type="text" name="subject" id="subject" placeholder="Subject" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" id="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
Send Message
Clear Form
</div>
</div>
</div>
</form>
</div>
</div>
<!-- Contact -->
<div class="wrapper wrapper-style4">
<article id="contact">
<header>
<h2>Want to hire me? Get in touch!</h2>
<span>I do quality work and would love to work for you!.</span>
</header>
<div>
<div class="row">
<div class="12u">
<div id="errors"></div>
<form method='post' action='mailform.php' id='contact-form'>
<div>
<div class="row half">
<div class="6u">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" name="email" id="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<input type="text" name="subject" id="subject" placeholder="Subject" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" id="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
Send Message
Clear Form
</div>
</div>
</div>
</form>
</div>
</div>
I need the JavaScript here:
<script>
</script>
And the PHP form is here:
<?php
$to = "bcw1995#gmail.com";
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$from = $_REQUEST['email'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail($_REQUEST['email'], $subject,
$message, "From:" . $email);
}
header("Location: http://www.thorbis.com/#contact");
?>
Can someone please fix this you will be a life saver!
You get two E-Mails:
Your mail is send twice, because you are calling two times the mail() function. Delete this line mail($to,$subject,$message,$headers);
// EDIT
change the second E-Mail function to this: mail($to, $subject, $message, "From:" . $email);
Else the sender will get the email that he has send.
Validation:
There are a lot of ways and librarys for a Javascript Form-Validation. I recommand jQuery + jQuery.Validation Plugin (http://jqueryvalidation.org/).
But i would also add a validation in the PHP file, because if somebody has disabled javascript, he can send empty emails.
I hope that i could help you.
Related
I am trying to get all the fields of a html form and sent them by email when the submit button is pressed.
But it doesn't work and I don't know why.
When I test the send button, nothing display in action.php page I don't know why.
I made method="post" and action=action.php in form tag.
HTML FORM
<form action="action.php" method="POST">
<div class="p pb-3"><strong>Feel free to contact me </strong></div>
<div class="row mb-3">
<div class="col">
<div class="input-group"><span class="input-group-addon"><i class="fa fa-user-circle"></i></span>
<input class="form-control" type="text" name="name" placeholder="Name" required="required"/>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<div class="input-group"><span class="input-group-addon"><i class="fa fa-file-text"></i></span>
<input class="form-control" type="text" name="subject" placeholder="Subject" required="required"/>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<div class="input-group"><span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input class="form-control" type="email" name="mail" placeholder="E-mail" required="required"/>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<div class="form-group">
<textarea class="form-control" name="message" placeholder="Your Message" required="required"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col">
<button class="btn btn-primary" type="submit" name="submit" value="Send">Send</button>
</div>
</div>
</form>
```.
PHP CODE
``` code
<?php
echo 'bonjour'
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$subjectF=$_POST['subject'];
$msg=$_POST['message'];
$to='boussidan.raphael#gmail.com';
$subject='Form Submission';
$message="Name :".$name."\n"."Subject :".$subjectF."\n"."Wrote the following :"."\n\n".$msg;
$headers="From: ".$email;
if(mail($to, $subjectF, $message, $headers)) {
echo "<h1>Sent Successfully! Thank you"." ".$name.", I will contact you shortly!</h1>";
echo "Message :"." ".$message. , .$subjectF., .$email.
}
else{
echo "<h1>Something went wrong!</h1>";
}
}
?>
If you are making website not on local server, php mail will be probably turned off, also try https://github.com/PHPMailer/PHPMailer it is if mail does not work, cuz from your question I did not understand what is not working. Another thing if you are doing your php code into another file, not in the file where your html, you don't have to put
if(isset($_POST['submit']))
because if you are doing it in another file it means you are already pressed button to make action in that file
I want to get an email from an html form. I was following a tutorial that used PHP, which I have never used before, and it doesn't seem to work. After I hit submit, the php page opens, but an email is not sent to me. Can someone please help me.
HTML(A couple inputs like name and email, etc. and a submit button at the bottom):
<form action="contact_form_process.php" method="POST">
<section id="contact" class="py-3">
<div class="container">
<div class="row">
<div class="col-md-9 mx-auto">
<div class="card p-4">
<div class="card-body">
<h3 class="text-center lato-font">Please Fill Out This Form To Contact Us</h3>
<hr>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input id="first_name" type="text" class="form-control" placeholder="First Name">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="last_name" type="text" class="form-control" placeholder="Last Name">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="email" type="text" class="form-control" placeholder="Email">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="phone_num" type="text" class="form-control" placeholder="Phone Number">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<textarea class="form-control" name="" id="message" rows="10" placeholder="Message"></textarea>
</div>
</div>
</div>
</div>
<div class="card-footer">
<input type="submit" class="btn btn-outline-success btn-block" value="Send">
<button type="submit" class="btn btn-outline-success btn-block">Send</button>
</div>
</div>
</div>
</div>
</div>
</section>
</form>
Here is my PHP:
<?php
// Subject and Email Variables
$emailSubject = 'Test Email';
$webMaster = 'tamiroffen#gmail.com';
// Gathering Data Variables
$first_nameField = $_POST['first_name'];
$last_nameField = $_POST['last_name'];
$emailField = $_POST['email'];
$phone_numField = $_POST['phone_num'];
$messageField = $_POST['message'];
$body = <<<EOD
<br><hr><br>
Email: $emailField <br>
Name: $first_nameField <br>
Phone Number: $phone_numField <br>
Message: $message <br>
EOD;
$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
?>
Thank you!
mail() needs to be enabled as #esqew points out in his comment - this would look something like this (this is on my BigRock environment YMMV) -
ini_set("include_path", '<path to php>' . ini_get("include_path") );
require_once "Mail.php";
Also, if you are using GMail, you also need to set up GMail to allow sending mail through SMTP - https://support.google.com/mail/answer/7126229?visit_id=636741342414654323-2069917091&hl=en&rd=1
$webMaster = 'tamiroffen#gmail.com';
I assume this is the address where the emails are sent to. From what I've heard, PHP mail() function doesn't work for gmail(if it's on the receiver end).
You can just use another email provider like hotmail or any and forward emails from it to your gmail
Watch this video if you need more info on it, How to create a PHP Contact Form Tutorial
Trying to send an email not displaying any error message or anything just refreshing the page that it.
I am trying an email through contact form but its not working.Here is the code for that. tried by doing echo but it is not working .not displaying any error as well.
contact and contactus:
<?php ob_start();
if(isset($_POST['submit'])) {
$to = "abc#gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$txt = $_POST['comment'];
$headers = "From: " .$email . "\r\n" .
"CC: xyz#gmail.com";
mail($to,$subject,$txt,$headers);
header("Location: contact.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>HMS System</title>
</head>
<body>
<div class="container">
<div class="page-header">
<h2>Contact Us Form</h2>
</div>
<form class="form-horizontal" action="contactus.php" method="post" role="form">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="name" placeholder="Insert your Name" id="name">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email Address</label>
<div class="col-sm-8">
<input type="email" class="form-control" name="email" placeholder="Email Address" id="email">
</div>
</div>
<div class="form-group">
<label for="subject" class="col-sm-2 control-label">Subject</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="subject" placeholder="Subject" id="subject">
</div>
</div>
<div class="form-group">
<label for="comments" class="col-sm-2 control-label">Comment</label>
<div class="col-sm-8">
<textarea class="form-control" rows="10" name="comment" style="resize:none;"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<input type="submit" value="Send Message" name="submit_contact" class="btn btn-block btn-danger" id="subject">
</div>
</div>
</form>
</section>
</article>
</div>
<div style="width:50px;height:50px;"></div>
</body>
use this
if(isset($_POST['submit_contact']))
If you are doing it from your local server, you will have to setup your mail properly in ini then only you will be able to send mail from your local machine.
A better approach would be to wrap the mail function in a statement. Mail is returning a bool value. And beginn as simple as possible.
error_reporting (E_ALL);
$to = "mail#whatever.com"
// ... your settings ...
if ( mail ( $to , $subject , $message ) ) {
// do when ok
}
else {
// do when error
}
To verify that you receive all values from $_POST do
echo '<pre>';
print_r ($_POST);
echo '</pre>';
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
So I have this HTML code for my contact form:
<section id="contact-form">
<form action="form.php" method="post" enctype="multipart/form-data">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="block">
<form>
<div class="form-group">
<input type="text" class="form-control" placeholder="Ime" name="name">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Email Adresa" name="email">
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" placeholder="Predmet">
</div>
</form>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="block">
<form>
<div class="form-group-2">
<textarea class="form-control" rows="3" placeholder="Poruka" name="message"></textarea>
</div>
<button class="btn btn-default" type="submit">Pošalji</button>
</form>
</div>
</div>
</div>
</div>
</form>
</section>
And my PHP script looks like this:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Kontakt s web-stranice';
$to = 'myEmailAddress';
$subject = 'Kontakt s web-stranice ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email!</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message again.</p>';
}
}
?>
And for some reason when I click on the submit button the web page refreshes and the message isn't sent to my email.
Does anyone know why?
Your HTML format is using forms within forms, so everything outside that <form> tag is not being collected. All you need to do is have the first <form> tag and wrap all your input boxes and the submit button in it.
Notice in the code below how you only need one <form>.
<section id="contact-form">
<form action="form.php" method="post" enctype="multipart/form-data">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="block">
<div class="form-group">
<input type="text" class="form-control" placeholder="Ime" name="name">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Email Adresa" name="email">
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" placeholder="Predmet">
</div>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="block">
<div class="form-group-2">
<textarea class="form-control" rows="3" placeholder="Poruka" name="message"></textarea>
</div>
<button class="btn btn-default" type="submit">Pošalji</button>
</div>
</div>
</div>
</div>
</form>
</section>
Your PHP code is correct from the looks of things, but that messed up form tag was the big problem.
This question already has an answer here:
Making an Email Form Send Email
(1 answer)
Closed 9 years ago.
I have the following code for an email form from an HTML template. I'd like to make it send email, as the moment I think it doesn't and I need to add some PHP to process the form. Any tips on how to do that for this form?
Thank you!
<!-- Email -->
<article id="email" class="panel">
<header>
<h2>Email Me</h2>
</header>
<form action="#" method="post">
<div class="5grid">
<div class="row">
<div class="6u">
<input type="text" class="text" name="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" class="text" name="email" placeholder="Email" />
</div>
</div>
<div class="row">
<div class="12u">
<input type="text" class="text" name="subject" placeholder="Subject" />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Send Message" />
</div>
</div>
</div>
</form>
</article>
You should read http://php.net/manual/es/function.mail.php
so you get your data with $_POST and then treated data, to use something like this:
$message = wordwrap($message, 70, "\r\n");
mail('myMail#example.com', 'subject', $message);