why does this php contact form just download contact.php? - php

i'm a total n00b when it comes to PHP (and arguably, web development in general :/), but i've taken a look at a ton of examples, comparing my code, and i just can't figure it out. basically all thats happening is the contact.php file is just getting downloaded to my computer. ugh. also, this client did not ask for any field validation, which is why theres none there. help!!
heres my html-
<form action="contact.php" method="post">
<fieldset>
<legend><strong>Get A Quote!</strong>
</legend>
Call me at 555-555-5555, or email me at email#emaiul.com, or use the form below.<br /><br />
<div class="clearfix">
<div class="input">
<input style="width:370px; height:35px; font-size:14px;" value="Name" name="name" size="50" type="text">
</div>
</div><!-- /clearfix -->
<div class="clearfix">
<div class="input">
<input style="width:370px; height:35px; font-size:14px;" value="Email" name="email" size="50" type="text">
</div>
</div><!-- /clearfix -->
<div class="clearfix">
<div class="input">
<input style="width:370px; height:35px; font-size:14px;" value="Phone" name="phone" size="50" type="text">
</div>
</div><!-- /clearfix -->
<div class="clearfix">
<div class="input">
<textarea style="width:370px; height:55px; font-size:14px;" name="message" size="50" type="text">Message</textarea>
</div>
</div><!-- /clearfix -->
</fieldset>
<button type="submit" name="saveForm" style="background-image: url(static/img/btn-submit.png); width:150px; height:37px;"></button>
</form>
and the php-
<?php
if(isset($_POST['saveForm'])) {
$to = "steven#urethrafranklin.org";
$subject = "Inquiry from website";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$phone_field = $_POST['phone'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
mail($to, $subject, $body);
} else {
echo "Sorry, something went wrong. Please email me at user#user.com.";
}
?>

Ah, you guys are all right.
tail -f /var/log/mail.log
was helpful.
And I am now using validate.js. Thanks guys!

Related

Php mail not submitting and blank page displaying

I am using Ampps on Mac and trying to send an email using php from a contact form however I do not receive the mail and when the form is submitted it redirects me to the file page resulting in a blank display
my form :
<form action="email.php" method="post">
<div class="col-md-6 w3_agileits_contact_left">
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-22" name="Name" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-22">
<span class="input__label-content input__label-content--akira">Your name</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="email" id="input-23" name="Email" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-23">
<span class="input__label-content input__label-content--akira">Your email</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-24" name="Subject" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-24">
<span class="input__label-content input__label-content--akira">Your subject</span>
</label>
</span>
</div>
<div class="col-md-6 w3_agileits_contact_right">
<div class="w3_agileits_contact_right1">
<textarea name="Message" id="Message" placeholder="Your comment here..." required=""></textarea>
</div>
<div class="w3_agileits_contact_right2">
<input type="submit" value="Send">
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</form>
my File :
$email = $_POST['Email'];
$name = $_POST['Name'];
$to = "lucvanrooyen#gmail.com";
$subject = $_POST['Subject'];
$userMessage =$_POST['Message'];
$headers = "From: $email\n";
$message = "$name has sent you the following message.\n
Message: $userMessage";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: lucvanrooyen#gmail.com\n";
$usermessage = "Thank you for your enquiry we will be in touch.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
The code you have shown is not enough to debug your problem.
If you are using the mail method which is built into the standard library, read this answer to find out a few troubleshooting steps you could follow.
If you are and are still finding it difficult to use, then you could consider using one of the PHP emailing solutions like -
PHPMailer
SwiftMailer
Please check your form tag. there is no opening tag for form
<form action="email.php" method="post">

Unable to get informations from a Html5 CSS and php form

I try to build a html5 form and send informations to form.php
<h3>Contact Me</h3>
<p></p>
<form method="post" action="form.php">
<div class="row uniform">
<div class="6u 12u(xsmall)">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="6u 12u(xsmall)">
<input type="email" name="email" id="email" placeholder="Email" />
</div>
</div>
<div class="row uniform">
<div class="12u">
<input type="text" name="subject" id="subject" placeholder="Subject" />
</div>
</div>
<div class="row uniform">
<div class="12u">
<textarea name="message" id="message" placeholder="Message" rows="6"></textarea>
</div>
</div>
<div class="row uniform">
<div class="12u">
<ul class="actions">
<li>
<input type="submit" class="special" value="Send Message" />
</li>
<li>
<input type="reset" value="Reset Form" />
</li>
</ul>
</div>
</div>
</form>
At the same place I have form.php
<?
if (isset($_POST['name']) && isset($_POST['email'])) {
echo 'name '.$_POST['name'].' mail '.$_POST['email'];
}
?>
When I click on submit form.php page is open but blank.
<?php
if (isset($_POST['name']) && isset($_POST['email'])) {
echo 'name '.$_POST['name'].' mail '.$_POST['email'];
}
?>
I think you missed the opening of PHP tag its <?php and not <? .
Yes sorry, now I can send by mail.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: lespizz';
$to = 'jim#fdfrdsfg.com';
$subject = 'Hello';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
mail ($to, $subject, $body, $from)
?>
do you know how to get back on index.html automatically ?
Thanks
Using PHP you may redirect to another page with this code :
header("Location: index.html");
die();
But beware - it will work only if there was no output before!
Or if you have to give some output earlier you may just echo Javascript to redirect :
echo '<script type="text/javascript">
window.location = "http://www.google.com/"
</script>';

Cannot POST /.php file when submitting form for email

I'm trying to get a HTML from to work together with PHP in order to make a form for sending a mail, but after submitting the form, PHP file is saying
Cannot POST /quotation.php
Here is my HTML code
<div id="quotation" class="reveal-modal" data-reveal>
<a class="close-reveal-modal">×</a>
<h3>Request Quotation</h3>
<p>Please fill out this information and we will contact you as soon as possilble.</p>
<form method="post" name="" action="quotation.php">
<div class="row">
<div class="large-6 columns">
<label>Name
<input type="text" name="name" placeholder="Name" />
</label>
</div>
<div class="large-6 columns">
<label>Lastname
<input type="text" name="lastname" placeholder="Lastname" />
</label>
</div>
</div>
<div class="row">
<div class="large-6 columns">
<label>Company name
<input type="text" name="company" value="" placeholder="Your company">
</label>
</div>
<div class="large-6 columns">
<label>E-mail
<input type="text" name="email" value="" placeholder="E-mail">
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Additional details
<textarea name="message" placeholder="Additional details here"></textarea>
</label>
</div>
</div>
<input class="button radius" type="submit" name='submit' value="submit">
</form>
</div>
And this is the PHP that runs the form
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$company = $_POST['company'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = $visitor_email;//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name, $lastname.\n".
"Here is the message:\n $message".
$to = "email#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
alert("yo");
//done. redirect to thank-you page.
header('Location: index.html');
?>
I added alert and echo for submit button, but none of them appears so looks like PHP is not even running.
It would be great if someone could guide me trough this problem or point out what am I doing wrong.

Contact Form Problems (Red Border Validation)

I have been searching the web for two days for some sort of PHP template (because I do not know how to code in PHP) that could highlight a borders red if the user did not enter all the proper information. I manage to get the contact form working but not the way I want. Essentially, I need the user to enter proper information; if not, a red border appears.
Current Situation:
[Basic Contact Form: No Validation]
Desired Situation:
[Validating Contact Form]
*
Name (Required)(If Error: Red Border)
Email (Required: At least including the # sign)(If Error: Red Border)
Subject (Required)(If Error: Red Border)
Message (Required)(If Error: Red Border)
*
My site is: www.haildark.com, if you want to see it in its full detail. Please help if you can. I think my brain is about to implode again. Thank you. It does not have to be in PHP. As long as the code gets the job done, its perfectly fine with me.
HTML:
<!-- Contact -->
<div class="wrapper wrapper-style5">
<article id="contact" class="container small">
<header>
<h2>
Contact Us
</h2>
<span>
If you have any questions, comments, or concerns, please contact below and we will respond as soon as we can.
Please allow us at least 72 hours to respond. Thanks for supporting us.
</span>
</header>
<div>
<div class="row">
<div class="12u">
<form method="post" action="contact.php">
<div>
<div class="row half">
<div class="6u">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" name="email" id="email" placeholder="Email" />
</div>
</div>
<div class="row half">
<div class="12u">
<input type="text" name="subject" id="subject" placeholder="Subject" />
</div>
</div>
<div class="row half">
<div class="12u">
<textarea name="message" id="message" placeholder="Message">
</textarea>
</div>
</div>
<div class="row">
<div class="12u">
<a href="#" class="button form-button-submit">
Send Message
</a>
<a href="#" class="button button-alt form-button-reset">
Clear Form
</a>
</div>
</div>
</div>
</form>
</div>
</div>
Basic PHP:
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_subject = $_POST['subject'];
$field_message = $_POST['message'];
$mail_to = 'info#domain.com';
$subject = 'HailDark® User: '.$field_subject." - ".$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Subject: '.$field_subject."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers = 'Reply To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to info#domain.com');
window.location = 'index.html';
</script>
<?php
}
?>
I have seen that you are using HTML5 but not completely. You used:
<input type="text" name="email" id="email" placeholder="Email" />
You can use
<input type="email" name="email" id="email" placeholder="Email" required="required"/>
Html5 provides powerful way to manage your site like as the above line I used type="email" it automatically validates the email and also required="required" attribute provides you this field must not be empty it will highlighted you.
So use at first <!DOCTYPE html> before <html> tag and use html5 tags and use required="required" attribute for every tag where you want to validate the field.
<?php
if(empty($_POST['test'])) // other validation
{
$error = true;
}
?>
<input type="text" name='test' class='<?php echo ($error)?"red-border":"green-border"; ?>' />
<input type='submit' value='send' />
<style type="text/css">
.red-border{
border: 1px solid red;
}
.green-border{
border: 1px solid green;
}
</style>

How to Get Contact Form Working

Okay so I am fairly new to web designing. How do I get the contact form on my current theme to work? This is the current html.
I need to know how to code the PHP file; is this correct?
<div class="form row-fluid clearfix">
<div class="field span5">
<label>Your name:</label>
<input type="text" value="" class="req" placeholder="Placeholder text..." />
</div>
<div class="field span5">
<label>Your email:</label>
<input type="email" value="" class="req" />
</div>
<div class="clearfix"> </div>
<div class="field full">
<label>Your comment:</label>
<textarea class="span12" cols="2" rows="7"></textarea>
</div>
<button class="extruded"><span>Submit</span></button>
</div>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: iclear';
$to = 'sales#tangledindesign.com';
$subject = 'Hello';
?>
And how do I link the PHP file for that contact form?
Step 1
Wrap your fields with a form HTML element that has its action property set to your php processing page
Step 2
Name the form fields according to what the php file expects
Step 3
Add some validation
Step 4
Submit and test
Example
HTML
<form action="process.php" method="post">
First Name: <input type="text" name="first_name">
<input type="submit">
</form>
PHP
<?php
$first_name=$_POST["first_name"];
if($first_name=="John")
{
echo "Hi John!";
}
else
{
echo "Sorry Buddy, Don't really know you";
}
?>
Note
The reason why i did not provide you a full solution is that you mentioned you are a newbie in that programming, and it would be injustice to just solve your problem and not guide you how to do it
You need to wrap your HTML with the tag, and don't forget to get include the submit button:
<form action="process.php" method="post">
<div class="form row-fluid clearfix">
<input type="text" name="name">
<input type="text" name="email">
<input type="text" name="message">
<input type="submit" name="submit">
</div>
</form>
Then here is the php (process.php) file to get all values from your HTML form:
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: iclear';
$to = 'sales#tangledindesign.com';
$subject = 'Hello';
Hope this help.
Try this code
<?php
$toaddress ="youremail#domain.com" //change to your email address
$error ="";
if($_SERVER['REQUEST_METHOD']=="POST") {
$name=$_POST['name'] ;
$email=$_POST['email'] ;
$comment=$_POST['comment'] ;
if(!isset($name) || $name==""){
$error .="Please Enter your name <br/>";
}elseif (!isset($email) || $email==""){
$error .="Please Enter your email Address.<br/>";
}elseif(!isset($comment) || $comment==""){
$error .="Please Enter your Comments.<br/>";
}
if ($error ==""){
mail($toaddress,"Contact form",$comment)
}
}
?>
<?php echo $error ;?>
<form method='post' action='' enctype='multipart/form-data' id='news_form' name='post_form' >
<div class="form row-fluid clearfix">
<div class="field span5">
<label>Your name:</label>
<input name="name" type="text" value="" class="req" placeholder="Placeholder text..." />
</div>
<div class="field span5">
<label>Your email:</label>
<input type="email" value="" class="req" name="email" />
</div>
<div class="clearfix"> </div>
<div class="field full">
<label>Your comment:</label>
<textarea class="span12" cols="2" rows="7" name="comment"></textarea>
</div>
<input type="submit" value="submit" />
</div>
</form>

Categories