trying to get feedback as email from a contact form - php

I have a created a html form and a php file (mail.php) and i have added this in my form <form action="mail.php" method="POST">
but When I try to submit the form, instead of emailing me and providing the thank you message, it downloads the php page. When I run the .html page in my browser, it shows up fine but when I click send it downloads mail.php, instead of working.
Any suggestions?
ok this is the code
mail.php:
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$comments = $_POST['comments'];
$formcontent=" From: $name \n telephone: $telephone \n comments: $comments";
$recipient = "lllkk#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" ;
test.html:
<form action="mail.php" method="POST">
<div class="row">
<div class="form-group col-md-8 col-md-offset-1">
<input type="text" name="name" placeholder="Name" class="form-control">
</div>
<div class="form-group col-md-8 col-md-offset-1">
<input type="email" name="email" placeholder="Email" class="form-control">
</div>
<div class="form-group col-md-8 col-md-offset-1">
<input type="tel" name="telephone" placeholder="telephone" class="form-control">
</div>
<div class="clearfix"></div>
<div class="form-group col-md-8 col-md-offset-1">
<textarea class="form-control" name="comments" placeholder="Comments" rows="6"></textarea>
</div>
</div>
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>

Related

html/php contact form template not sending email

I'm using an html/php form template that I found. Every time I try to submit a completed form, I get a 405 error.
I want the submit button to send the contents of the form to my email address.
Heres the html:
<div class="col-md-6">
<form action="../assets/php/actionpage.php" name="emailform" method="POST">
<div class="row mb--20">
<div class="col-sm-6 col-md-12 col-lg-6 form-group">
<input type="text" class="form-control" placeholder="Name" />
</div>
<div class="col-sm-6 col-md-12 col-lg-6 form-group">
<input type="text" class="form-control" placeholder="E-mail" />
</div>
<div class="col-sm-6 col-md-12 col-lg-6 form-group">
<input type="text" class="form-control" placeholder="Phone" />
</div>
<div class="col-sm-6 col-md-12 col-lg-6 form-group">
<input type="text" class="form-control" placeholder="Website" />
</div>
<div class="col-12 form-group">
<textarea cols="30" rows="5" class="form-control" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="col-lg-6 offset-lg-6 form-group">
<button class="btn btn-block btn--border-primary"><input type="submit" value="submit"></button>
</div>
</div>
</form>
</div>
This doesn't look out of the ordinary to me. So I think the problem is with the php.
actionpage.php:
<?php
if ( !empty($_POST) ) {}
if(!isset($_POST['submit']))
{
//This page shouldn't be accesed directly
echo "ERROR: you need to submit the form!";
exit;
}
// Collect
$name = $_POST['Name'];
$email = $_POST['E-mail'];
$phone = $_POST['Phone'];
$website = $_POST['Website'];
$message = $_POST['Message'];
// Validate
if(empty($name)||empty($email)||empty($message))
{
echo "Name, E-mail, and Message are mandatory!";
exit;
}
$email_from = $email;
$email_subject = "New Form Submission";
$email_body = "You have a new email from: $name\n their email: $email\n phone number: $phone\n and their website: $website\n Here is their message: $message";
$to = "######.##" // my email
$headers = "From $email_from \r\n";
// Send
mail($to, $email_subject, $email_body, $headers);
// redirect
header('Location: index.html');
?>
I am very new to php, so I decided to use a template.
I'm testing this using LiveServer in VScode. Is that having an impact?

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");
?>

PHP Contact form sending no content in emails

I need help, i'm trying to set up a contact form, I have the code and think I have it set up correctly with HTML and PHP. When I submit to test it on my testsite it send an email through but the email is blank.
Thanks in advance if you can help me please.
HTML:
<div class="col-md-6 contact-right">
<form name="contactform" action="mailer.php" method="post" role="form" enctype="text/plain">
<div class="styled-input agile-styled-input-top">
<input type="text" class="form-control" name="name" placeholder="Your Name">
<label for="name">Name</label>
<span></span>
</div>
<div class="styled-input">
<input type="text" class="form-control" name="email" placeholder="Your Email">
<label for="email">Email</label>
<span></span>
</div>
<div class="styled-input">
<input type="text" class="form-control" name="subject" placeholder="Subject">
<label for="subject">Subject</label>
<span></span>
</div>
<div class="styled-input">
<textarea class="form-control" rows="4" name="message" placeholder="Your message..."></textarea>
<label for="message">Message</label>
<span></span>
</div>
<input type="submit" value="Submit" name="submit">
</form>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "laura#ironcladdesign.co.uk";
$subject = "Enquiry from CK9C Website";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We will be in touch very soon";
?>
The problem is here:
<form name="contactform" action="mailer.php" method="post" role="form" enctype="text/plain">
You are encoding as "text/plain". Replace with "application/x-www-form-urlencoded" which is the default or don't include enctype and that will be the default.
you can try it in place of $_POST
if ((!is_array($_POST)) || (count($_POST) < 1)) {
$_POST = json_decode(file_get_contents('php://input'), true);
}

contact form php failed

I have a problem with my contact form. When testing it I receive an email with no content. Just empty input titles "from: (empty) Message: (empty)".
PHP CODE
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "mymail#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
HTML CODE FORM
<form method="post" action="mail.php">
<div class="row 50%">
<div class="6u">
<input name="name" placeholder="Name" type="text" class="text" />
</div>
<div class="6u">
<input name="email" placeholder="Email" type="text" class="text" />
</div>
</div>
<div class="row 50%">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row 50%">
<div class="12u">
Send Message
</div>
</div>
</form>
You are not passing a form because you simply link to mail.php with your <a>. The way you are doing it, $_POST will always be empty as your form isn't submitted.
Please change this line
Send Message
to
<input type="submit" class="button alt" value="Send Message"/>

Contact form doesn't work on phone (works everywhere else)

I've made this php which will send me messages right to my inbox. Even though the script works fine on desktops and laptops I can't use on phones. Why is this happening? Am I doing something wrong? ( I tried the form on iPhone 6+ and Samsung Alpha)
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "info#mydomain.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: message-sent.html#contact'); exit();
?>
And this is the html code for the phone.
<form method="post" action="mail.php">
<div class="row 50%">
<div class="6u">
<input name="name" placeholder="Name" type="text" class="text" />
</div>
<div class="6u">
<input name="email" placeholder="Email" type="text" class="text" />
</div>
</div>
<div class="row 50%">
<div class="12u">
<textarea name="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row 50%">
<div class="12u">
<input type="submit" class="button alt" value="Send Message"/>
</div>
</div>
</form>
Thank you all in advance for your help.

Categories