PHP: Contact us form does not echo success text - php

I have two html forms that both send emails successfully using PHP. However, one form echo successful submission text, but the other one does not.
Here is the form that is part of the index.html page, which does not echo any text after submission. Please note, the email still sends:
<form class="booking-form" id="myForm" action="#">
<div class="row">
<div class="col-lg-12 d-flex flex-column">
<input name="name" placeholder="Your name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Your Name'" class="form-control mt-20" required="" type="text">
</div>
<div class="col-lg-6 d-flex flex-column">
<input name="subject" placeholder="subject" onfocus="this.placeholder = ''" onblur="this.placeholder = 'subject'" class="form-control mt-20" required="" type="text">
</div>
<div class="col-lg-6 d-flex flex-column">
<input name="email" placeholder="Email" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Email'" class="form-control mt-20" required="" type="email">
</div>
<div class="col-lg-12 flex-column">
<textarea rows="5" class="form-control mt-20" name="message" placeholder="Messege" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Messege'" required=""></textarea>
</div>
<div class="col-lg-12 d-flex justify-content-end send-btn">
<button type="submit" class="genric-btn primary mt-20 text-uppercase ">Send</button>
</div>
</div>
</form>
The following is the PHP mailer code:
<?php
$to = 'myEmail#gmail.com';
$firstname = $_POST["name"];
$email= $_POST["email"];
$text= $_POST["message"];
$subject= $_POST["subject"];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: Email coming from Brave Towing " . $email . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "
<html>
<head>
</head>
<body style=\"background-color:#fafafa;\">
<div style=\"padding:20px;\">
Customer Email: <span style=\"color:#888\">$email</span>
<br>
Contact Subject: <span style=\"color:#888\">$subject</span>
<br>
Contact Message: <div style=\"color:#888\">$text</div>
</div>
</body>
</html>
";
if (#mail($to, $email, $message, $headers))
{
echo '<h1>The message has been sent</h1>';
}else{
echo 'failed';
}
?>

Related

adding a success message to a html form with php

I´m tring to add a success message to my form after you click submit, but i dont know how, i have tried different code from different websites, but they dont work with my code. What line do i need to add to this code please?
<form action="contact.php" method="post" id="contact">
<h1>Contact-me!</h1>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="name">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="name#example.com">
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<textarea name="message" class="form-control" id="message" rows="3"></textarea>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary mb-3" value="SEND MESSAGE">Submit</button>
<div>
</div>
</div>
</form>
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = '';
$email_subject = "New Form Submission";
$email_body = "User Name: $name.\n".
"User Email: $visitor_email.\n".
"User Message: $message.\n";
$to = "";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: index.html");
?>

Bootstrap 4 form not sedning any messages

My bootstrap 4 form is not sending any messages, I've uploaded the index.php and contact.php files on the server and I'm not having any response. Would you be able to help me find the problem?
Landing page with simple form
<form id="#contacts" method="POST" class="form" role="form">
<div class="row">
<div class="col-md-6 form-group">
<input class="form-control" id="name" name="name"
placeholder="Podaj swoje Imię i nazwisko" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="website" name="website"
placeholder="Adres strony www" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="telephone" name="telephone"
placeholder="Podaj swój numer telefonu" type="text" required/>
</div>
<div class="col-md-6 form-group">
<input class="form-control" id="email" name="email"
placeholder="Podaj swój email" type="email" required/>
</div>
</div>
<textarea class="form-control" id="message" name="message" placeholder="Twoja wiadomość"
rows="4"></textarea>
<br>
<div class="row">
<div class="col-md-12 form-group">
<button class="btn btn-primary" type="submit">Wyślij</button>
</div>
</div>
</form>
contact.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$website = $_POST['website'];
$telephone = $_POST['telephone'];
$email_from = 'SEO';
$email_subject = 'Wiadomość kontaktowa z... '
$email_body = "Name: $name.\n".
"Email: $email.\n".
"Message: $message.\n";
"Website: $website.\n";
"Telephone: $telephone.\n";
$to = "biuro#of.pl";
$headers = "From: $email_from r\n";
$headers .= "Reply-To: $email r\n";
mail($to,$email-$email_subject,$email_body,$headers);
header("location: index.php");
?>
Your form is missing Action
<form id="#contacts" method="POST" class="form" role="form" action="contact.php">

how can i send php mail with html contact form

I am currently trying to send an HTML contact form or the contents of it using php mail () function. Just hang up and ask for help.
How can I e.g. Your entered text and the email address specified in the contact form via PHP?
So my code looks currently and it works .. Only I do not know how I the data entered and send it with ..
HTML CODE:
<form class="" action="senden.php" method="post">
<div class="">
<label>Name</label>
<input type="text" name="von" placeholder="Bitte geben Sie Ihren Namen ein" value="">
<label>E-Mail Adresse</label>
<input type="text" name="email" placeholder="Bitte geben Sie Ihre Email-Adresse ein" value="">
<label>Telefonnummer</label>
<input type="tel" name="tel" placeholder="Bitte geben Sie Ihre Telefonnummer ein" value="">
</div>
<div class="">
<label>Nachricht</label>
<textarea placeholder="Bitte geben Sie Ihre Nachricht ein" name="nachricht" rows="8" cols="40"></textarea>
<button type="submit" name="submit" value="">Nachricht Abschicken</button>
</div>
</form>
`
PHP CODE:
<?php
$empfaenger = "mymail#gmail.com";
$betreff = "Mail Function";
$from = "From: Max Reimers <absender#domain.de>";
$text = "Email Email Email Email Text Text Text";
mail($empfaenger, $betreff, $text, $from);
?>
Here is Code:
<form class="form-horizontal" action="" id="contact-form" method="post">
<fieldset>
<legend class="text-center colheader">Email Us</legend>
<div class="form-group">
<div class="col-md-10 col-md-offset-1">
<input id="name" name="name" type="text" placeholder="Full Name" class="form-control" required>
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-1">
<input id="email" name="email" type="text" placeholder="Email Address" class="form-control" required>
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-1">
<input id="phone" name="phonenumber" type="text" placeholder="Phone" class="form-control" required>
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-1">
<input id="subject" name="subject" type="text" placeholder="Subject" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-1">
<textarea class="form-control" id="message" name="messag" placeholder="Enter your massage for us here. We will get back to you within 2 business days." rows="7" required></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12 text-center">
<button type="submit" name="submit" class="btn btn-primary btn-lg">Submit</button>
</div>
</div>
</fieldset>
</form>
<?php
if(isset($_POST['submit'])) {
$to = 'ourmail#example.com';
$from = $_POST['email'];
$subject ='Adlivetech Contact Form';
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phonenumber'];
$subject = $_POST['subject'];
$messag = $_POST['messag'];
$message = '<html><body>';
$message .='<table>';
$message .='<tr><td>Name:</td><td>'. $name .'</td></tr>';
$message .='<tr><td>Email:</td><td>'. $email .'</td></tr>';
$message .='<tr><td>Phone:</td><td>'. $phone .'</td></tr>';
$message .='<tr><td>Subject:</td><td>'. $subject .'</td></tr>';
$message .='<tr><td>Message:</td><td>'. $messag .'</td></tr>';
$message .='</table>';
$message .='</body></html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "To: {$to}\r\n";
$headers .= "From: {$name} <{$from}>\r\n";
$headers .= "Reply-To: <{$to}>\r\n";
$headers .= "Subject: {$subject}\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
mail($from, $subject, $message, $headers);
}
?>

PHP: Interactive Contact form not working

Why is this form not working?
I'm creating a form that sends messages to users.
The user email comes from the database.
The query that searches the database is influenced by some data sent previously to the browser.
The problem at the moment is:
When one clicks to submit, nothing really happens.
Got a file called mini-contact.php with the following:
Script to proccess the form:
<?php
var_dump($_POST);
error_reporting(E_ALL);
$company=$_GET['company'];
$sql = "SELECT * FROM companies WHERE companies.companyID= '$company'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$companyemail = $row['Email_Address'];
if(isset($_POST['submit'])){
$to = "tiagomartinsperes#gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = $_POST['subject'];
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$header = "From:" . $from;
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";
$header2 = "From:" . $to;
$header2.= "MIME-Version: 1.0\r\n";
$header2.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header2.= "X-Priority: 1\r\n";
$status1 = mail($to,$subject,$message,$header);
$status2 = mail($from,$subject2,$message2,$header2); // sends a copy of the message to the sender
if($status1 and $status2){
$first_name = $_POST['first_name'];
echo 'Mail Sent. Thank you' . $first_name . ', we will contact you shortly.';
} else {
echo '<p>Something went wrong, Please try again!</p>';
}
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
}
?>
The actual form:
<form id="contact-form" method="post" action="">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>First Name *</label>
<input type="text" name="first_name" class="form-control" placeholder="Please enter your first name" required="required" data-error="First name is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>Last Name *</label>
<input type="text" name="last_name" class="form-control" placeholder="Please enter your last name" required="required" data-error="Last name is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" placeholder="Please enter your email" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6 col-sm-6 no-left-pad">
<div class="form-group">
<label>Phone</label>
<input type="tel" name="phone" class="form-control" placeholder="Please enter your phone">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 no-left-pad">
<div class="form-group">
<label>Subject</label>
<input type="text" name="subject" class="form-control" placeholder="Example: Service Request ">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 no-left-pad">
<div class="form-group">
<label>Message *</label>
<textarea name="message" class="form-control" placeholder="Please enter your message" rows="4" required="required" data-error=" Please enter your message."></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-12 no-left-pad">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</div>
<div class="col-md-12 no-left-pad">
<input type="submit" class="btn btn-default caps" name="submit" value="Submit">
</div>
</div>
</div>
</form>
What am I doing wrong?
Thank you for your time
One needs to have SMPT properly configure so that it works.

Unable to receive email from simple ajax php contact

Hi I'm trying develop a simple contact form in php. I have done a lot of research but can't seem to solve this.
Here is the HTML code:
<form id="contact-form" action="contact.php" method="post" class="clearfix">
<div class="contact-box-hide">
<div class="col-sm-6">
<input type="text" class="form-control" id="first_name" name="first_name" required placeholder="First Name">
<span class="first-name-error"></span>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" id="last_name" name="last_name" required placeholder="Last Name">
<span class="last-name-error"></span>
</div>
<div class="col-sm-6">
<input type="email" class="form-control" id="contact_email" name="contact_email" required placeholder="Email Address">
<span class="contact-email-error"></span>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" id="subject" name="contact_subject" required placeholder="Subject">
<span class="contact-subject-error"></span>
</div>
<div class="col-sm-10">
<textarea class="form-control" rows="5" id="message" name="message" required placeholder="Message"></textarea>
<span class="contact-message-error"></span>
</div>
<div class="col-sm-2">
<button id="contact-submit" class="btn custom-btn col-xs-12" type="submit" name="submit"><i class="fa fa-rocket"></i></button>
<span id="contact-loading" class="btn custom-btn col-xs-12"> <i class="fa fa-refresh fa-spin"></i> </span>
</div>
</div><!-- /.contact-box-hide -->
<div class="contact-message"></div>
</form><!-- /#contact-form -->
And this is the PHP portion:
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$contact_email = $_POST['contact_email'];
$contact_subject = $_POST['contact_subject'];
$message = $_POST['message'];
$subject = "New Message from Website Form";
$submit = $_POST['submit'];
if($submit){
//Prepare Email
$from = 'From: My Website'."\r\n";
$to = 'odeleon#outlook.com';
$subject = "Message from United Passions for Christ.org";
$body = "".
"From: ".$first_name."\n".
"E-mail: ".$contact_email."\n".
"Message: ".$message."\n";
//Send email
if(mail($to, $subject, $body, $from)){
echo '<p>Your message has been sent!</p>';
}
}
?>
he contact form shows up OK and there aren't any php errors when the user hits submit. However the email never appears in my inbox. Any ideas?
Is there something that I'm missing from this?
Check php.ini file configuration, you can find that in /etc/ directory.
Refer this http://www.tutorialspoint.com/php/php_sending_emails.htm
Try
if(isset($_POST['submit'])){
//your code to submit
}

Categories