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"/>
Related
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);
}
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>
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.
I,m trying to make a form send an e-mail but im getting page not found error.
This is the form itself
<form action="sendmail.php" method="post">
<div>
<div class="row half">
<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 half">
<div class="12u">
<input type="text" class="text" name="subject" placeholder="Subject" />
</div>
</div>
<div class="row half">
<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>
And this is the PHP file named sendmail.php
<?php
$to = "info#aroundgalaxy.pt";
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
//$site = $_REQUEST['site'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$headers = "noreply#aroundgalaxy.pt";
$body = "From: $name \n\n Email: $email \n\n Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
else
{echo "<script language=javascript>window.location = 'LINK BACK TO CONTACT PAGE';</script>";}
?>
Am i missing something?
Thanks
The code should work. I dont think there is a problem with the code. Just make sure both the form page & sendmail.php are on the same directory
I'm currently working on a HTML form that uses PHP to send a message to email. I'm testing in MAMP and am unable to get a response after clicking "send message". Any advice would be much appreciated.
HTML
<form action="mail.php" method="POST">
<div class="row half">
<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 half">
<div class="12u">
<textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
<br />
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li class="button form" input type="submit" value="Submit">Send Message</li>
</ul>
</div>
</div>
</form>
PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$to = 'my#email.com';
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$send_message=mail($to, $subject, $formcontent, $mailheader);
if($send_message){
echo "thank you"
} else {
echo "error";
}
?>
Thanks
found some errors in ur code
correct this:
<li class="button form" input type="submit" value="Submit">Send Message</li>
to
<li class="button form"> <input type="submit" value="Submit">Send Message</li>
correct this:
echo "thank you"
to echo "thank you";
Are you checking this in your local server? php mail() function may probably not work in local servers.Check it in some online servers(after correcting the bugs mentioned by #Ashish ).
HTML
<form action="mail.php" method="POST">
<div class="row half">
<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 half">
<div class="12u">
<textarea name="message" placeholder="Message" rows="6" cols="25"></textarea>
<br />
</div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li class="button form"> <input type="submit" value="Submit" name="sendmessage"/>Send Message</li> // Use name attribute
</ul>
</div>
</div>
*Use Name Attribute *
PHP
<?php
if($_POST['sendmessage']!="")
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$to = 'my#email.com';
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$send_message=mail($to, $subject, $formcontent, $mailheader);
if($send_message){
echo "thank you";
} else {
echo "error"; }
}
?>
Try this code.