I am beginner in web developing, I am building a website which has contact form and when the details are entered the details has to be sent to my mail id. But I am not sure why the code is not working.
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["name"]==""||$_POST["email"]==""||$_POST["note"]==""){
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['email'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Invalid Sender's Email";
}
else{
$message = $_POST['note'];
$headers = 'From:'. $email2 . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email2 . "\r\n"; // Carbon copy to Sender
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("[ email removed ]", $message, $headers);
echo "Your mail has been sent successfuly ! Thank you for your feedback";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hire-a-Tent</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<![endif]-->
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<!-- Javascript -->
<script src="js/jquery.placeholder.js"></script>
<script src="js/custom.js"></script>
<!-- Fav and touch icons -->
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<div class="background">
<div class="wrapper">
<header>
<div class="tel"><span>CALL US:</span> 9738479234 <br /><span style="padding-left:150px;">9731015469</span></div>
<div class="social">
<img src="images/facebook.png" alt="" />
<img src="images/twitter.png" alt="" />
</div>
</header>
<div class="sidebar">
<div class="order-form">
<div class="order-form-head">
<h1>Rent -a- Tent</h1>
</div>
<div class="taxi-line"></div>
<!-- Contact Form -->
<form action="email_code.php" id="form" method="post" name="form">
<div class="inp"><input type="text" class="required" name="name" id="name" placeholder="Name..." /></div>
<div class="inp"><input type="text" class="required" name="tel" id="tel" placeholder="Telephone..." /></div>
<div class="inp"><input type="text" class="required" name="email" id="email" placeholder="Email..." /></div>
<div class="inp"><textarea class="required" name="note" id="note" placeholder="Message..."></textarea></div>
<button type="submit"></button>
<div class="spacer"></div>
</form>
<?php include "email_code.php"?>
</div>
<div class="address-box">
<img src="images/icon.png" class="icon" alt="" />
<div class="text">
<span>We are located at</span><br />
85, 4th cross road,<br />
GKW layout, vijayanagar<br />
Bengaluru-40
</div>
</div>
</div>
<div class="character">
<!-- <img src="images/transparent2.png" class="taxi-driver" alt="" /> -->
<marquee behavior="alternate">T2 Tent: Rs 100/day --- T3 Tent: Rs 200/day -- Sleeping Bag: Rs 50/day --</marquee>
</div>
<div class="spacer"></div>
<footer>
<p><strong><br/><br/>Hire-a-tent</strong> © All Rights Reserved. <!--Developed by the Frequency Themes --></p>
</footer>
</div>
</div>
</body>
</html>
There are a few things wrong here, so please go over my entire answer carefully.
Firstly, your entire code's execution is relying on the conditional statement it's set in:
if(isset($_POST["submit"])){...}
where it is looking for and is relying on a named attribute of the same name, which would most likely be your submit button being:
<button type="submit"></button>
It needs to be named:
<button type="submit" name="submit"></button>
or use an input type with a name attribute:
<input type="submit" name="submit" value="Submit">
Then you have an undefined variable $email2 which would most likely need to be $email, as per:
$email=$_POST['email'];
Having used error reporting, would have both signaled an "Undefined index submit..." warning, as well as "Undefined variable email2...".
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
Now, this line:
mail("[ email removed ]", $message, $headers);
It is missing the "subject" parameter, which is an important parameter when using mail().
I.e.:
mail("[ email removed ]", $subject, $message, $headers);
therefore, you will need to add a variable for it.
I.e.:
$subject = "Form submission";
For more information on mail() and headers, visit:
http://php.net/manual/en/function.mail.php
From the manual:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
To check if mail() has been in fact executed, change:
mail("[ email removed ]", $message, $headers);
to
if(mail("[ email removed ]", $message, $headers)){
echo "Mail has been sent.";
}
else{
echo "Error. Check your mail logs.";
}
If/when you see "Mail has been sent.", then mail() has done its job.
If you don't receive mail, then check your Spam or contact your hosting company if you're on a hosted site.
If you're running this from your own computer, then make sure that PHP and mail are in fact installed, running and configured properly.
Footnotes:
You're using the following twice, which one of them can be safely removed:
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
EDIT:
To add other form variables to the message, first declare the POST variables:
$name=$_POST['name'];
$email=$_POST['email'];
$tel=$_POST['tel'];
Then change $message = $_POST['note']; to $comment = $_POST['note'];
and then do:
$message = "$name\n$email\n$tel\n$comment";
The \n adds line breaks.
Related
So I'm in a web design class in school right now and I want to set up a contact page that will send the results to my email. I followed a really good tutorial and made sure I typed everything correct but it wont send. I'm using freehosting.com to host my pages.
Here's my index.php:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<meta charset="UTF-8">
<title>Email Form</title>
</head>
<body>
<main>
<p class="header">E-MAIL FORM</p>
<form class="contact-form" action="contactform.php" method="post">
<p class="title">Your Name</p>
<input type="text" name="name" placeholer="Full Name"><br/>
<p class="title">Your E-Mail</p>
<input type="text" name="mail" placeholer="Your E-mail"><br/>
<p class="title">Subject</p>
<input type="text" name="subject" placeholer="Subject"><br/>
<p class="title">Message</p>
<textarea name="message" maxrows="10" placeholder="Message"></textarea><br/>
<button type="submit" name="submit"><h2>SUBMIT</h2></button><br/>
</form>
</main>
</body>
Here's my contactform.php:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "terryjtowell#terrytowell.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an Email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}
Any help would be great. I'm new to PHP but really familiar with html. the live link for the test contact form is terrytowell.com/test/index.php I've made sure to upload my code to a live hosting service so that I'll be able to use server-side scripting. Thanks
Your code is right. The problem comes from your hosting.
Freehosting.com won't allow you to use mail() function unless you pay for an addon. It's all explained here -> https://www.freehosting.com/client/knowledgebase.php?action=displayarticle&id=25
So I am basically trying to create a simple photography portfolio website, and decided to put in a contact page as well. Right now I am trying to build a basic email submission form with php but when I inputted the values in the webpage the values disappeared, but I did not receive any emails. I was wondering if the cause is some error in my code, or if I have to turn the webpage into a website for it to send emails.
For furthermore information: I am using xampp to test out the php code and my file directories are: C:\xampp\htdocs and inside the htdocs is a folder called "Photo Website" which has all my webpages, and images.
I ran it through localhost using http://localhost/Photo%20Website/Contact.php and got
Warning : mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\Photo Website\Contact.php on line 46
<!DOCTYPE html>
<html ng-app>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.7/angular.min.js">
</script>
<link rel="stylesheet" type="text/css" href="webpage.css">
</head>
<div id="nav">
<ul>
<li> Contact </li>
<li> About Me </li>
<li> Business </li>
<li> Street </li>
<li> Nature </li>
</ul>
<p id="logo"> Icyportraitsgta </p>
</div>
<div id="description">
<!-- Creating the contact forms using HTML !-->
<form method="post" name="emailform" action="Contact.php">
Enter Name: <input type="text" name="name"> <br>
Enter Email: <input type="text" name="email"> <br>
Message: <textarea name="message"></textarea> <br>
<input type="submit" value="Send">
</form>
<!-- Assigned variables using php and used POST !-->
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<!-- Using the above php variables to compose an email message !-->
<?php
$email_from = 'alihaider2011#live.ca';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message";
?>
<!-- php code to send the email !-->
<?php
$to = "dutchland2013#hotmail.com";
$headers = "From: $email_from \r\n";
$headers = "Reply-To: $visitor_email \r\n";
mail($to, $email_subject,$email_body, $headers);
?>
</div>
</body>
</html>
I don't know what I'm doing wrong. I am trying to use PHP to make a contact me form. Here is the code:
<?php
if($_POST["submit"]) {
$recipient="qdpicks#gmail.com";
$subject="Form to email message";
$Name=$_POST["Name"];
$Email=$_POST["Email"];
$Reason=$_POST["Reason"];
$Message=$_POST["Message"];
$mailBody="Name: $Name\nEmail: $Email\n\n$Reason $Message";
mail($recipient, $subject, $mailBody, "From: $Name <$Email>");
$thankYou="<p>Thank you! Your message has been sent.</p>";
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="QDPicks.css">
<title> QDPicks</title>
</head>
<body>
<header>
<a class="btn btn-primary btn-lg" href="QDPicks.html" role="button">Home</a>
<a class="btn btn-sample btn-lg active pull-right" href="QDPicksContactUs.html" role="button">Contact Us</a>
<a class="btn btn-sample btn-lg pull-right" href="QDPicksCompany.html" role="button">Company</a>
<a class="btn btn-sample btn-lg pull-right" href="QDPicksProducts.html" role="button">Products</a>
</header>
<header><p1>Contact Us</p1></header>
<form method="post" action="QDPicksContactUs.php >
<div class="form-group">
<label for="InputReason1"></label>
<input type="text" class="form-control" id="InputReason1" name="Name">
<label for="exampleInputEmail1"></label>
<input type="email" class="form-control" id="exampleInputEmail1" name="Email">
<label for="InputReason1"></label>
<input type="text" class="form-control" id="InputReason1" name="Reason">
</div>
<div class="form-group">
<textarea type="text" class="form-control" rows="3" name="Message"> </textarea>
<p3 class="help-block">Explain on the reason for contact.</p3>
</div>
<div class="checkbox">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"> </script>
</body>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</html>
When I put my info in and hit submit the data goes away like it has sent an email but no email has come in. Also sorry - for some reason some of the code got cut off but it isn't any crucial parts.
You forget to put " after action="QDPicksContactUs.php
Replace your tag with this line
<form method="post" action="QDPicksContactUs.php" >
May be your code works after this change
First of all there is a missing double quote here
<form method="post" action="QDPicksContactUs.php >
Also there is no need to give the page name in the action if you are posting at the same page.
Add name in tag like:
<button name="submit" type="submit" class="btn btn-default">Submit</button>
Finally replace if($_POST["submit"]) with if(isset($_POST["submit"]))
Also, are you running your code on localhost?
Let's focus on the code that sends the email. Please read my comments.
if($_POST["submit"]) {
// you probably shouldn't post a real email here on SO
$recipient="qdpicks#gmail.com";
$subject="Form to email message";
// you should validate this field if you are sticking it in your mail headers as you do below.
$Name=$_POST["Name"];
// you should DEFINITELY validate this before trying to send mail
$Email=$_POST["Email"];
$Reason=$_POST["Reason"];
$Message=$_POST["Message"];
$mailBody="Name: $Name\nEmail: $Email\n\n$Reason $Message";
// first, you don't even bother checking to see if this returns TRUE
// secondly, because you don't validate $Name or $Email, this command is vulnerable to Mail Header Injection
mail($recipient, $subject, $mailBody, "From: $Name <$Email>");
$thankYou="<p>Thank you! Your message has been sent.</p>";
}
So your form is bad because you don't validate anything, you don't check to see of the mail command actually returned a successful result, and it's vulnerable to Mail Header Injection.
First, validate the $Name:
$Name=$_POST["Name"];
if (!preg_match('/^[a-zA-Z_\-]+$/', $Name)) {
die("sorry! Name is not valid");
}
Second, validate $Email
$Email = $_POST["Email"];
if (!filter_var($Email, FILTER_VALIDATE_EMAIL)) {
die("Sorry, email is not valid");
}
Third, check the result of your mail function. If it returns FALSE or an otherwise empty value, something went wrong -- although we probably won't be able to find out what without asking a sysadmin to look at a mail log.
if (!mail($recipient, $subject, $mailBody, "From: $Name <$Email>")) {
die("OH NO. The mail function did not work.");
}
Consider reading the manual on the mail function:
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
I am using Dreamweaver to create a website, my website has a form, but when I click on the submit button it opens my outlook application, with the information I want. I was just wondering if it was possible to send the email to my account without going through my email client. This is my code...
BTW I am using Dreamweaver to edit all the code.
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fiction Filming</title>
<link rel="shortcut icon" href="images/favicon3.ico" type="image/x-icon" />
<style type="text/css">
body {
background-color: #2c2c2c;
}
</style>
<link href="Css/singlePageTemplate.css" rel="stylesheet" type="text/css">
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.-->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/source-sans-pro:n2:default.js" type="text/javascript"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Main Container -->
<div class="container">
<!-- Navigation -->
<!-- Hero Section -->
<!-- About Section -->
<!-- Stats Gallery Section -->
<div class="gallery"><img src="Images/Newbannercomingsoon.png" alt="" width="1000" height="500" class="logo-pic"/> </div>
<!-- Parallax Section -->
<!-- More Info Section -->
<!-- Footer Section -->
<section class="footer_banner" id="contact">
<form class="subscribeForm form-fix" name="Subscription Form" method="post" action="mailform.php" enctype="text/plain">
<div class="newform">
<div> </div>
<div>
<input id="fname" type="text" placeholder="NAME" name="name" required>
</div>
<div>
<input name="email" type="email" required id="email" placeholder="EMAIL">
</div>
<div>
<select name="select" required id="myselect">
<option>HELP / SUPPORT</option>
<option>BUSINESS ENQUIRES</option>
<option>OTHER</option>
</select>
</div>
<div class="text-form">
<div>
<textarea name="textarea" required id="textarea" placeholder="TYPE YOUR TEXT HERE"></textarea>
</div>
</div>
<br><input name="Send" type="submit" id="Send" value="Send">
</div>
</form>
<!-- Step 1: Add an email field here -->
<!-- Step 2: Add an address field here -->
<!-- Step 3: add a submit button here -->
</section>
<!-- Copyrights Section -->
<div class="copyright">©2016 - <strong>Fiction filming</strong></div>
</div>
<!-- Main Container Ends -->
</body>
</html>
Also, here is my php file... If you can fix it, it would be really helpful.
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset="UTF-8">
<META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
$to = "example#example.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$sender_name = $_POST['name'];
$select = $_POST['select'];
$message = $sender_name . " wrote the following:" . "\n\n" . $_POST['textarea'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
</body>
</html>
HERE IS THE NEW PHP
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset="UTF-8">
<META HTTP-EQUIV="refresh" content="3;URL=thankyou.html">
<title>Email Form</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
// Or the below if using "name="Send" for the input. Uncomment and get rid of the above
// if(isset($_POST['Send'])){
if(!empty($_POST['email'])
&& !empty($_POST['name'])
&& !empty($_POST['select'])
&& !empty($_POST['textarea'])) {
$to = "mail#fictionfilming.com";
$from = $_POST['email'];
$sender_name = $_POST['name'];
$select = $_POST['select'];
$textarea = $_POST['textarea'];
$message = $sender_name . " wrote the following:" . "\n\n" . $textarea;
if(mail($to,$subject,$message,$headers)){
echo "Mail was sent. Check both your inbox and spam, as mail as done its job.";
}
else{
echo "There was a problem. Check your logs.";
}
}
}
// $headers = "From:" . $from;
// $headers2 = "From:" . $to;
//echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
//}
?>
</body>
</html>
There are a few issues with your code.
Firstly, remove enctype="text/plain". That type isn't valid to send POST arrays with a form.
You should also remove <META HTTP-EQUIV="refresh" content="0;URL=thankyou.html"> as that may play some nasty tricks on you.
Then your input <input name="Send" type="submit" id="Send" value="Send"> bears the Send name attribute and you're using the following conditional statement which will never fire up:
if(isset($_POST['submit']))
Either rename your input to name="submit", or your conditional statement to read as if(isset($_POST['Send'])); the choice is yours.
Error reporting would have thrown you something about it.
Now, I don't see why you have this in your code $headers2 = "From:" . $to; since it's not being used anywhere, therefore I can't say much about this, other than just to get rid of it.
You should also check for empty fields, should someone decide not to fill any or all of the inputs, resulting in an empty email.
I.e., and I replaced your $_POST['textarea'] with $textarea while assigning it for the POST array.
Sidenote: See the above in regards to "submit" and "Send"; modify accordingly for the if(isset($_POST['submit'])) below here.
if(isset($_POST['submit'])){
// Or the below if using "name="Send" for the input. Uncomment and get rid of the above
// if(isset($_POST['Send'])){
if(!empty($_POST['email'])
&& !empty($_POST['name'])
&& !empty($_POST['select'])
&& !empty($_POST['textarea'])) {
$from = $_POST['email'];
$sender_name = $_POST['name'];
$select = $_POST['select'];
$textarea = $_POST['textarea'];
$message = $sender_name . " wrote the following:" . "\n\n" . $textarea;
// Put your other mail code here
}
}
All this assuming that mail() is available on the server you are running this from.
I suggest you replace:
mail($to,$subject,$message,$headers);
with a conditional statement, in order to check if it was sent:
if(mail($to,$subject,$message,$headers)){
echo "Mail was sent. Check both your inbox and spam, as mail as done its job.";
}
else{
echo "There was a problem. Check your logs.";
}
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
Sidenote: Displaying errors should only be done in staging, and never production.
Footnotes:
I noticed you are using ID's, so if you're using JS/Ajax/jQuery that you didn't include in your original question, would be beyond the scope of the question.
It is unknown as to how you are accessing your files, so if you are on a hosted site, then what I have given you should work.
If it is a server issue, then that also is beyond the scope of the question and you will need to contact your service provider for tech support.
If you're using this from your own PC, then PHP, a webserver and mail() need to be installed, properly configured and using http://localhost/file.xxx as opposed to file:///file.xxx.
Sidenote: If nothing is passed from <option>, then you may have to give them values.
I.e.: <option value="HELP / SUPPORT"> while doing that for the others.
I believe I have given you enough to move ahead here.
Since in the form tag u mentioned the action as action="mailto:mail#fictonfilming.com" it is trying to access outlook
change the action to the name of your php file
action="yourphpfilename.php"
Depending on your server configuration, you may not be able to send mails using the simple php mail function.
To test it, use:
print mail($to,$subject,$message,$headers);
If the result is not 1, something is not good, and fixing it maybe not be easy.
I suggest you use the PHPmailer or API based services like MailGun.
I am trying to set up a contact form at:
http://48hrcodes.com/contact.php
however I am trouble getting it to work.
Here is the code I am using:
<?php
/**
* Change the email address to your own.
*
* $empty_fields_message and $thankyou_message can be changed
* if you wish.
*/
// Change to your own email address
$your_email = "";
// This is what is displayed in the email subject line
// Change it if you want
$subject = "48hrcodes contact form";
// This is displayed if all the fields are not filled in
$empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>";
// This is displayed when the email has been sent
$thankyou_message = "<p>Thank you. Your message has been received.</p>";
// You do not need to edit below this line
$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);
if (!isset($_POST['txtName'])) {
?>
<html lang="en">
<head>
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="css/style.css">
<title>Free 48hr Xbox Live Gold Codes</title>
</head>
<body>
<div id="content">
<div id="c1"> <center>
<header id="nav">
<ul>
<li>Home</li>
<li>Get Your Code</li>
<li>Testimonials and Proof</li>
<li>Frequently Asked Questions</li>
<li>Contact Us</li>
</ul>
</header>
<img class="clear" src="img/grab3.png" alt="header">
</center>
<form class="form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p class="name">
<input type="text" name="txtName" id="name" placeholder="John Doe" />
<label for="name">Name</label>
</p>
<p class="email">
<input type="text" name="txtEmail" id="email" placeholder="mail#example.com" />
<label for="email">Email</label>
</p>
<p class="text">
<textarea name="txtMessage" placeholder="Write something to us" /></textarea>
</p>
<p class="submit">
<input type="submit" value="Send" />
</p>
</form>
<div id="cttxt">
<h3>
Contact Us
</h3>
<p>
Simply send us message using the contact form to the left and we will get back to you within 24-48 hours.
</p>
</div>
<center>
<footer>
© 48hrcodes.com 2013 - site by ollie rex
</footer>
</div></center>
</div>
</body>
</html>
<?php
}
elseif (empty($name) || empty($email) || empty($message)) {
echo $empty_fields_message;
}
else {
// Stop the form being used from an external URL
// Get the referring URL
$referer = $_SERVER['HTTP_REFERER'];
// Get the URL of this page
$this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
// If the referring URL and the URL of this page don't match then
// display a message and don't send the email.
if ($referer != $this_url) {
echo "You do not have permission to use this script from another URL, nice hacking attempt moron.";
exit;
}
// The URLs matched so send the email
mail($your_email, $subject, $message, "From: $name <$email>");
// Display the thankyou message
echo $thankyou_message;
}
?>
I get errors at the top of the page, as well as when i submit the form, the email i get only has the messagebox text, not the name or email.
I have tried everything i could think of, however it still fails to send anything except the msg variable.
Thanks :)
change
$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);
To,
$name = (isset($_POST['txtName']))?stripslashes($_POST['txtName']):"";
$email = (isset($_POST['txtEmail']))?stripslashes($_POST['txtEmail']):"";
$message = (isset($_POST['txtMessage']))?stripslashes($_POST['txtMessage']):"";
To avoid the warnings at the top.
Use
like this
if(isset($_POST['txtName'])
{
$name = stripslashes($_POST['txtName']);
}