I have PHP contact form and I want the Message sent or failed message to be displayed inside the main page.. I have tag after the submit button with id="notification" I want the message from send.php to be displayed inside of it.
My code is:
<form method="post" action="send.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Subject</label>
<input name="subject" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<button id="submit" name="submit" type="submit">Dergo</button>
<h3 id="notification" align="center" style="font-color:green;"></h3>
</form>
Send.php code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = 'From: KontaktFormular';
$to = 'albanianboy2#gmail.com';
$headers = "From:" . $email . "\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if(#mail($to,$subject,$body,$headers))
{
echo "Mesazhi juaj u dërgua me sukses";
}else{
echo "Gabim! Ju lutemi provoni përsëri.";
}
?>
Put your code in a PHP file.
Your code:
<?php session_start(); ?>
<form method="post" action="send.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Subject</label>
<input name="subject" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<button id="submit" name="submit" type="submit">Dergo</button>
<h3 id="notification" align="center" style="font-color:green;">
<?php
if(!empty($_SESSION["notification"])){
echo $_SESSION["notification"];
unset($_SESSION["notification"];
}
?>
</h3>
</form>
Your send.php file:
<?php
session_start();
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = 'From: KontaktFormular';
$to = 'albanianboy2#gmail.com';
$headers = "From:" . $email . "\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if(#mail($to,$subject,$body,$headers))
{
$_SESSION["notification"] = "Mesazhi juaj u dërgua me sukses";
}else{
$_SESSION["notification"] = "Gabim! Ju lutemi provoni përsëri.";
}
header("location: YOUR_PHP_FILE_WITH_THE_FORM ");
?>
Change this part of your code:
}else{
echo "Gabim! Ju lutemi provoni përsëri.";
}
to:
}else{
header('Location: mainpage.php?msg=1');
}
Then on main page, you can have:
<?php
if(isset($_GET['msg']) && $_GET['msg'] = 1)
{
?>
<h3 id="notification" align="center" style="font-color:green;">
Gabim! Ju lutemi provoni përsëri.
</h3>
<?php
}
?>
The message
$notification = "put your message";
The Javascript:
// Appeding notification to Body
$('#notification').html($notification);
Do this where you do your php check.
Put this css on top:
#notification{
display: none;
}
Setup your div
<div id="notification">
Related
So I'm trying to make a contact me form for a website and this is my first time making one of these forms. My issue is that for some odd reason my button is not sending anything and the button doesn't want to work.
This is the input form
<div>
<form id="contact-us" method="post" action="contact-form-handler.php">
<input name="name" type="text"class="form-control" placeholder="Your name" required>
<br>
<input name="phone" type="number" class="form-control" placeholder="Phonenumber no symbols or dashes"required>
<br>
<input name="email" type="email" class="form-control" placeholder="Your email" required>
<br>
<textarea name="message" class="form-control" placeholder="write us a message" rows="4" required></textarea>
<br>
<input type="submit" class="form-control-submit" value="SEND">
</form>
</div>
Here is my handler.
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$email_from = 'website.com';
$email_subject = 'New message from customer';
$email_body = "name: .$name. \n".
"email: .$visitor_mail.\n".
"phone: .$phone. \n".
"message: .$message. \n";
$to= "email#gmail.com";
$headers= $email_from.;
$headers .= $visitor_email.;
mail($to,$email_subject,$email_body,$headers);
header("Location: index.html");
?>
I'm not sure why this isn't working but if anyone could help me that would be amazing.
<div>
<form id="contact-us" method="post" action="contact-form-handler.php">
<input name="name" type="text" class="form-control" placeholder="Your name" required>
<br>
<input name="phone" type="number" class="form-control" placeholder="Phonenumber no symbols or dashes" required>
<br>
<input name="email" type="email" class="form-control" placeholder="Your email" required>
<br>
<textarea name="message" class="form-control" placeholder="write us a message" rows="4" required></textarea>
<br>
<input name="submit" type="submit" class="form-control-submit" value="SEND">
</form>
</div>
Handler
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$email_from = 'website.com';
$email_subject = 'New message from customer';
$email_body = "name: {$name} \n" .
"email: {$visitor_email}\n" .
"phone: {$phone} \n" .
"message: {$message} \n";
$to = "email#gmail.com";
$headers = $email_from;
$headers .= $visitor_email;
$res = mail($to, $email_subject, $email_body, $headers);
header("Location: index.html");
}
I found a few errors in your code:
$headers= $email_from.; // syntax error - need to remove dot before ;
$headers .= $visitor_email.; // syntax error - need to remove dot before; same here
In your email body, you used $visitor_mail variable, but your is $visitor_email
Also, I've added the name tag to your form and added an additional validation condition.
Please try to use this solution, I hope it will help you. This solution is working fine on my side
I am trying to fetch "user information" on my mail id through the "mail()" function in php.the mail() function worked fine previously but now it's not working.Here is my HTML code:
<form name="contactForm" class="standard-form row-fluid" action="contact.php" method="post" >
<input class="span6" name="themeple_name" placeholder="Name" type="text" id="themeple_name" value="" / style="float:left; background-color:#fff;">
<input class="span6" name="themeple_email" placeholder="E-Mail" type="text" id="themeple_email" value="" / style="background-color:#fff;">
<input class="span6" name="themeple_subject" placeholder="Subject" type="text" id="themeple_subject" value="" required>
<textarea class="span12" placeholder="Message" name="themeple_message" cols="40" rows="7" id="themeple_message" style="background-color:#fff;"></textarea>
<p class="perspective">
<input type="submit" value="Submit Form" class="btn-system normal default" /> </p>
</form>
This is my php file:
<?php
$headers = "From: xyz#gmail.com";
$to = "xyz#gmail.com";
$Email = $_POST['themeple_email'];
$Name = $_POST['themeple_name'];
$Subject = $_POST['themeple_subject'];
$Message = $_POST['themeple_message'];
$subject = "Form submission";
$email_message = "Form details below. \r\n";
$email_message .= "Name: ".$Name. "\r\n";
$email_message .= "Email: ".$Email. "\r\n";
$email_message .= "subject: ".$Subject. "\r\n";
$email_message .= "Message: ".$Message. "\r\n";
mail ($to, $subject, $email_message, $headers);
header("Location: thank-you.html");
//echo "MAIL SENT " . $Name . $Email . $Phone . $Message;
?>
Thanks in advance.
What's the best solution to make the name and email fields compulsory in my form?
Can't seem to find a direct solution for my form and no expert.
I'm currently receiving loads of blank emails.
HTML code
<form name="enq" method="post" action="mail/myphpfile.php" onSubmit="return validation();">
<fieldset>
<input type="text" name="name" id="name" value="" class="input-block-level" placeholder="Name" />
<input type="text" name="email" id="email" value="" class="input-block-level" placeholder="Email" />
<textarea rows="11" name="message" id="message" class="input-block-level" placeholder="Comments"></textarea>
<div class="actions">
<input type="submit" value="Send Your Message" name="submit" id="submitButton" class="btn btn-info pull-right" title="Click here to submit your message!" />
</div>
</fieldset>
</form>
PHP code
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$query = $_POST['message'];
$email_from = $name.'<'.$email.'>';
$to="name#myemailaddress.co.za";
$subject="Enquiry from my website";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$email_from."\r\n" . "BCC:email#email1.co.za, email#email2.co.za, email#email3.co.za\r\n";
$message="
Name: $name
<br>
Email-Id:$email
<br>
Message:$query";
if(mail($to,$subject,$message,$headers))
header("Location:../thank-you.html");
else
header("Location:../error.html");
//contact:-email#myemail.co.za
}
?>
Try
<?php
if(isset($_POST['submit']) && !empty($_POST['email']) && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false)
{
$name = $_POST['name'];
$email = $_POST['email'];
$query = $_POST['message'];
$email_from = $name.'<'.$email.'>';
$to="name#myemailaddress.co.za";
$subject="Enquiry from my website";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$email_from."\r\n" . "BCC:email#email1.co.za, email#email2.co.za, email#email3.co.za\r\n";
$message="Name: $name <br>
Email-Id:$emai<br>
Message:$query ";
if(mail($to,$subject,$message,$headers))
header("Location:../thank-you.html");
else
header("Location:../error.html");
//contact:-email#myemail.co.za
}
use html5 required validation like this
<input type="text" name="name" id="name" value="" class="input-block-level" placeholder="Name" required/>
<input type="email" name="name" id="name" value="" class="input-block-level" placeholder="Name" required/>
In HTML5 this should work fine!
<input type="text" name="name" id="name" value="" class="input-block-level" placeholder="Name" required/>
<input type="email" name="emailField" id="name" value="" class="input-block-level" placeholder="Email" required/>
try this!!
if(isset($_POST['submit']))
{
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL) && $email =="" ) {
$emailErr = "Enter valid email.";
}
else
{
$emailErr = "";
}
if( $emailErr==""){
mail($to,$subject,$message,$headers);
header("Location:../thank-you.html");
}
else
{
echo $emailErr;
header("Location:../error.html");
}
}
I've built a basic contact form using the following:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$message = $_POST['message'];
$from = 'From: Contact';
$to = 'info#mydomain.com';
$subject = 'message';
$body = "From: $name\n E-Mail: $email\n Contact Number: $contact\n Message:\n $message";
?>
<form id="contact-1" method="post">
<label>Name</label>
<input name="name" placeholder="YOUR NAME">
<label>Email</label>
<input name="email" type="email" placeholder="EMAIL ADDRESS">
<label>Contact Number</label>
<input name="contact" type="tel" placeholder="TELEPHONE">
<label>Message</label>
<textarea name="message" placeholder="MESSAGE"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
<?php
if ($_POST['submit'] ) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been submitted</p>';
} else {
echo '<p>Something went wrong, please try again!</p>';
}
}
?>
If you leave the name input blank and submit the form, its successful. However, if I add anything the name input. the form doesnt send and the site loads a 'page not found'.
Add type="text" into first input element.
This code appeared to have worked for me, test it out and see if the mail sends properly.
I added the
type="text"
to Name, and added
isset()
around
$_POST['submit']
I enclosed the top potion with
if (isset($_POST['submit']) ) {
To avoid errors before the page is first submitted.
<?php
if (isset($_POST['submit']) ) {
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$message = $_POST['message'];
$from = 'From: Contact';
$to = 'info#mydomain.com';
$subject = 'message';
$body = "From: $name\n E-Mail: $email\n Contact Number: $contact\n Message:\n $message";
}
?>
<form id="contact-1" method="post">
<label>Name</label>
<input type="text" name="name" placeholder="YOUR NAME">
<label>Email</label>
<input name="email" type="email" placeholder="EMAIL ADDRESS">
<label>Contact Number</label>
<input name="contact" type="tel" placeholder="TELEPHONE">
<label>Message</label>
<textarea name="message" placeholder="MESSAGE"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
<?php
if (isset($_POST['submit'])) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been submitted</p>';
} else {
echo '<p>Something went wrong, please try again!</p>';
}
}
?>
I want to use php and HTML to create a contact page so users can send me an message directly from the website to my email-account
The only problem I have is that, it doesn't send any messages to my email-inbox(no errors on page)
Here is the code:
HTML(no css style): INDEX.html
<!DOCTYPE html >
<html>
<head>
<title>Contact US</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="page-wrap">
<div id="contact-area">
SEND US A MESSAGE:
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="City">City:</label>
<input type="text" name="City" id="City" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
</div>
</div>
</body>
</html>
PHP: contactengine.php
<?php
$EmailFrom = "JhonDoe#domain.com";<-- not sure about this one
$EmailTo = "MyEmail#domain.com";
$Subject = "WebSite Message";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
?>