fading out php echo messages - php

I want to fade out php echo message. Here is my php code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$to = 'ajay.k#enexl.com';
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
$mailSubject = "Contact request from " .$name;
$txt = "name : ".$name.".\n\nSubject : ".$subject.".\n\nMail id : ".$email."\n\nMessage : ".$message;
$headers = "From: ".$email ;
mail($to,$mailSubject,$txt,$headers);
$data = array();
$data['status'] = 'success';
//echo json_encode($data);
echo "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>";
echo "<p id='#text'>Your email was sent! One of our team members would contact you shortly!</p>"; // success message
echo "<script type='text/javascript'>";
echo "$(function(){";
echo "$('#text').fadeOut(5000);";
echo "});";
echo "</script>";
}
else{
echo "Mail was not sent, make sure that all fields are filled in";
}
?>
When the form data gets submitted, successfully, I get the response as Your email was sent! One of our team members would contact you shortly!. However it doesn't fade out as expected. How can I make it fade out?

Dont use # in you id qualifier. #text says to find an element with id text not #text
echo "<p id='#text'>Your email was sent! One of our team members would contact you shortly!</p>"; // success message
should be
echo "<p id='text'>Your email was sent! One of our team members would contact you shortly!</p>"; // success message

Related

PHP Mailer: Specific Confirmations Messages based on Empty Fields

I have a Contact Form which submits the data using AJAX to a PHP mailer. Once the email have been sent a confirmation message is shown to the user. It works well. My problem is how to customize the confirmation message based on which fields have been filled.
The form has four fields. Name (required), Subject (option list: by default 'Subscribe to Newsletter'), Email (required) and Message and there are two cases:
1) User is only looking to get subscribed to the Newsletter. Only 'Name' and 'Email' fields are filled. Confirmation message A.
2) User sends an email. 'Name', 'Email' and 'Message' are filled. Confirmation message B.
This is my current code, shows a general confirmation message:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = strip_tags(trim($_POST["name"]));
$asunto = strip_tags(trim($_POST["asunto"]));
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
if ( empty($name) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
http_response_code(400);
echo "¡Error 400 bla bla...!
exit;
}
$recipient = "name#domain.com";
$subject = "Nauta $name";
$email_content = "Nombre: $name\n";
$email_content = "Asunto: $asunto\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Mensaje:\n$message\n";
$email_headers = "From: $name <$email>";
if (mail($recipient, $subject, $email_content, $email_headers)) {
http_response_code(200);
echo "¡Thank you! bla bla...";
}
else {
http_response_code(500);
echo "¡Error 500 bla bla...!
}
}
else {
http_response_code(403);
echo "¡Error 403 bla bla...!
}
I tried the following structure (elseif) with no luck.
if ( ) {
echo "...";
} elseif ( ) {
echo "...";
} else {
echo "...";
}
No results.
Try to ask if message is an empty string or one blank character:
if ($_POST['message']!="") {
...
}
Thank you, #Carmen. It didn't work but I have found the way to make it work.
if (empty($_POST['message'])) {
...
}

Message not sending in contact form

I'm trying to create a contact form where the user will fill out their name, email, subject and message in order to contact me. It is suppose to send an email to my email account but every time i test it, it does not work. I was positive it was correct, but i guess it is not. Any help please?
<?php
//Get user input
$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"]
$message = $_POST["message"];
//error messages
$missingName = '<p><strong>Please enter your name!</strong></p>';
$missingEmail = '<p><strong>Please enter your email address!</strong></p>';
$invalidEmail = '<p><strong>Please enter a valid email address!</strong></p>';
$missingSubject = '<p><strong>Please enter a Subject!</strong></p>';
$missingMessage = '<p><strong>Please enter a message!</strong></p>';
//if the user has submitted the form
if($_POST["submit"]){
//check for errors
if(!$name){
$errors .= $missingName;
}else{
$name = filter_var($name,FILTER_SANITIZE_STRING);
}
if(!$email){
$errors .= $missingEmail;
}else{
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
$errors .=$invalidEmail;
}
}
if(!$subject){
$errors .= $missingSubject;
}else{
$message = filter_var($subject, FILTER_SANITIZE_STRING);
}
if(!$message){
$errors .= $missingMessage;
}else{
$message = filter_var($message, FILTER_SANITIZE_STRING);
}
//if there are any errors
if($errors){
//print error message
$resultMessage = '<div class="alert alert-danger">' . $errors .'</div>';
}else{
$to = "fanonxr#gmail.com";
$subject = "Contact";
$message = "
<p>Name: $name.</p>
<p>Email: $email.</p>
<p>Subject: $subject.</p>
<p>Message:</p>
<p><strong>$message</strong></p>";
$headers = "Content-type: text/html";
if(mail($to, $subject, $message, $headers)){
$resultMessage = '<div class="alert alert-success">Thanks for your message. We will get back to you as soon as possible!</div>';
header("Location: index.php");
}else{
$resultMessage = '<div class="alert alert-warning">Unable to send Email. Please try again later!</div>';
}
}
echo $resultMessage;
}
?>
it seems you are missing the form action and mailto since its Html i think those should be included.
your validation looks good to me.
In terms of sending email, try finding some answers here:
PHP mail form doesn't complete sending e-mail
If that doesn't address your question, please provide some more info, like what mailer you're using. Hope this helps :)

PHP form to returning all the information

I am a complete novice when it comes to php, I have got the below php which sends me back the 'message' and sends an auto response to the user, as well as redirecting them to the 'thank you' page. Problem I am having is that it won't return the users name that they fill in on the form, any ideas?
<?php
$youremail = "ally.baird81#gmail.com"; //this is where the email will be sent to
#extract($_POST);$name = filter_var($name, FILTER_SANITIZE_STRING);
$message = filter_var($message, FILTER_SANITIZE_STRING);
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (mail($youremail, 'Message from website.', $message, "From: Krew Kut Hair<$email>")) {
$autoreply = "Thank you for enquiring at Krew Kut Hair, we will be in contact shortly";
$subject = "Thank you for your enquiry!";
mail($email, $subject, $autoreply, "From: Krew Kut Hair<$email>");
}
} else {
echo "Please enter a valid email address";
}
header("Location: thanks.html");
Assuming the name is in one of the form fields, you should be able to retrieve it. As Barmar says - all you have to do is use it somewhere in the body or the message. How can you tell the name is missing if you don't echo it out somewhere.
Try this:
$autoreply = "Thank you ".$name." for ...
If the name is still "missing" - you can try to see all the post variables like this:
echo "<PRE>Post Vars\n"; print_r($_POST);
If you have an input named "name" like:
<input type="text" name="name" value="" />
Check if it's containing data with e.g. :
echo 'The value of name is ['.$name.']';
If it is containing data you just can use the $name variable in your message. If it isn't there is probably something wrong in your HTML form.
<?php
$youremail = "ally.baird81#gmail.com"; //this is where the email will be sent to
#extract($_POST);$name = filter_var($name, FILTER_SANITIZE_STRING);
$message = filter_var($message, FILTER_SANITIZE_STRING);
$content = "<strong>Name:<strong><br />".$name."<br />";
$content .= "<strong>Message:<strong><br />".$message."<br />";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (mail($youremail, 'Message from website.<br />', $content, "From: Krew Kut Hair<$email>")) {
$autoreply = "Hi ".$name.". Thank you for enquiring at Krew Kut Hair, we will be in contact shortly";
$subject = "Thank you for your enquiry!";
mail($email, $subject, $autoreply, "From: Krew Kut Hair<$email>");
}
} else {
echo "Please enter a valid email address";
}
header("Location: thanks.html");
Also read the comments on your question. I strongly recommend to find an other way instead of using extract().

Create success message on php form submit

I'm trying to make a php mail form display a success message upon a successful submit.
I'm new to php and I'm not sure how to make this work.
As it sits now, after submit, the site just reloads at the top of the page. I'd like it to refresh at the contact div and display a success message.
Contact div html:
<div class="contact-wrapper" >
<div class="contact">
<div class="contact-left" id="contact">
<?php
if (isset($_REQUEST['email'])) {
echo "Thank you for your message.";
}
$mail_form = include('php/mail_form.php'); ?>
</div> <!-- end div contact -->
Contact from PHP:
<?php
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['email']))
{//if "email" is filled out, proceed
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE)
{
echo "Invalid input";
}
else
{//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("idc615#gmail.com", "Subject: $subject",
$message, "From: $email" );
header("location: index.php");
}
}
?>
Try this code... You need to halt your script for some time so that user can see success or failure message. Without sleep user will not be able to see message as header will execute immediately.
if(mail("idc615#gmail.com", "Subject: $subject",$message, "From: $email" )){
echo "Thank you for your message";
sleep(2); // sleep for 2 seconds. Enough to display success message
//header will execute after 2000ms(2s)
header("location: index.php");
}else{
echo "Unable to send message";
sleep(2); // sleep for 2 seconds
header("location: index.php");
}
or try code given below:
in Contact from PHP
if(mail("idc615#gmail.com", "Subject: $subject",$message, "From: $email" )){
header("location: index.php?status=1");
}else{
header("location: index.php?status=0");
}
in index.php
if(isset($_GET['status'])){
$status = $_GET['status'];
if($status == 1){
echo "Thank you for your message";
}else if($status == 0){
echo "Unable to send message";
}
}
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$message = mysql_real_escape_string($_POST['message']);
if(isset($_POST['contactrgtr']))
{
$query = "insert into contact_us(name,email,message)values('$name','$email','$message')";
$res = mysql_query($query);
if($res){
$message = 'Your Message Successfully Sent';
include_once('contact.php'); } `
Then in contact.php page you have to define <?php $message ?>.

php contact form with reply message

I created a contact form that uses my php script to email the form parameters:
//File email.php
<?php
include('variables.php');
$to = "info#timeshare.org.uk";
$subject = "Quote From Website";
$name = $_POST["name"];
$email = $_POST["email"];
$number = $_POST["number"];
$resort = $_POST["resort"];
$headers = "From: ".$to."\r\n";
$message = "Name: ".$name."\r\n".
"Email: ".$email."\r\n".
"Number: ".$number."\r\n".
"Resort Name:".$resort."\r\n";
if (mail($to,$subject,$message,$headers)){
$replyHeader = "Thank You!";
$replyMessage = "Thank you for using our quick contact form. We will get back to you as soon as possible.";
}else{
$replyHeader = "Oops!";
$replyMessage = "An Error Occured whilst trying to send the form. Please try again later";
}
header( 'Location: http://localhost/TimeShare/formReturn.php' ) ;
?>
on submit the form action points to this code.
Now if the mail function is successfull, i want the form to redirect to formReturn.php, however i want the content in a particular div to show the $replyHeader and $replyMessage.
So once the form is posted, it redirects to a page that either displays a successfull message or an error message.
Now on my formReturn.php page ive tried including the variables Like so:
//File: formReturn.php
<body>
//Header code...
//sidebar code...
<div>
<?php include('php/email.php'); ?>
<h1> <?php echo $replyHeader; ?> </h1>
<p> <?php echo $replyMessage ?> </p>
</div>
//Footer code...
</body>
Problem with this code is, because im including the email.php file, i end up with a redirection loop. Which is bad!
So how would i get the variables $replyHeader and $replyMessage onto the page in that specific location depending on the success or failure of the mail() function
You can also add a GET-variable to your second page:
if($mail_is_succesfull)
header('Location: http://localhost/TimeShare/formReturn.php?success=true');
else
header('Location: http://localhost/TimeShare/formReturn.php?success=false') ;
Then you can add the message in your other page.
you could pass it as a get variable
<?php
include('variables.php');
$to = "info#timeshare.org.uk";
$subject = "Quote From Website";
$name = $_POST["name"];
$email = $_POST["email"];
$number = $_POST["number"];
$resort = $_POST["resort"];
$headers = "From: ".$to."\r\n";
$message = "Name: " . $name . "\r\n".
"Email: " . $email . "\r\n".
"Number: " . $number . "\r\n".
"Resort Name:". $resort . "\r\n";
if (mail($to,$subject,$message,$headers)){
$replyHeader = "Thank You!";
$replyMessage = "Thank you for using our quick contact form. We will get back to you as soon as possible.";
header( "Location: http://localhost/TimeShare/formReturn.php?header={$replyHeader}&message={$replyMessage}" ) ;
}else{
$replyHeader = "Oops!";
$replyMessage = "An Error Occured whilst trying to send the form. Please try again later";
header( "Location: http://localhost/TimeShare/formReturn.php?header={$replyHeader}&message={$replyMessage}" ) ;
}
?>
//File: formReturn.php
<body>
<div>
<h1> <?php echo $_GET['header'] ?> </h1>
<p> <?php echo $_GET['message'] ?> </p>
</div>
</body>
just update your email thing to send email and redirect ONLY IF
if (isset($_POST["email"])){
}
otherwise you know that form is not submitted and that you don't want to bother about sending email.
and as others suggested, you have to append some get param to the url, like Snicksie (header('Location: http://localhost/TimeShare/formReturn.php?success=[1|0]');)
suggested. then on your script you check for that variable to see if you should show anything.
e.g.
if (isset($_GET["success"])){
if ($_GET["success"] == 1){
show success message
} else {
show error message
}
}

Categories