PHP not working correctly? - php

I have this PHP code here, which should sent the Names, Email and comment of the user to an email. Although it doesn't seem to be working any more. I've been using this code as a basis for my contact form for many years. Now they're just not working.
Your message is being sent...
<?php
$emailSubject = 'A message from: '.$_POST['name'] .' '.'-'.' ' .'Email Adress: ' .$_POST['email'];
$webMaster = 'webmaster#gmail.com';
$name1 = $_POST['name1'];
$name2 = $_POST['name2'];
$email = $_POST['email'];
$sub = $_POST['sub'];
$comments = $_POST['comments'];
$body = <<<EOD
<br><hr><br>
<b>First Name: $name1 </b><br>
<b>Last Name: $name2 </b><br>
Email: $email <br>
Subject: $sub <br>
Comments: $comments <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);
$theResults = <<<EOD
<html>
<head>
<title>Your message is being sent...</title>
<meta http-equiv="refresh" content="4;URL=http://www.google.co.uk">
<style type="text/css">
<!--
body {
background-color: #25EA5F;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #30489E;
text-decoration: none;
padding-top: 350px;
margin-left: 550px;
width: 800px;
}
-->
</style>
</head>
</html>
</body>
EOD;
echo "$theResults";
?>
It's very confusing and annoying. Messages when sent to Hotmail don't even appear, so that'll force the clients to get a new email because of it, and when sent to Google... Does it not accept $_POST or something?
As you can see, the SCRIPT does work, it's just with G-mail none of the important information seems to show up, and on Hotmail the messages don't even send/appear!! Thanks for your help. Here is the HTML if needed.
<div class="contactwrap">
<div class="ContactInner">
<div class="ContactTitle">CONTACT US</div>
<form action="Scripts/contact.php" method="post">
<div class="containboxes">
<span id="sprytextfield1">
<label for="text1"></label>
<input name="text1" type="text" class="inputstyle" id="name1" value="First Name" size="5" maxlength="5" />
<span class="textfieldRequiredMsg"></span></span>
<span id="sprytextfield2">
<label for="text2"></label>
<input name="text2" type="text" class="inputright" id="name2" value="Last Name" />
<span class="textfieldRequiredMsg"></span></span>
<span id="sprytextfield3">
<label for="text3"></label>
<input name="text3" type="text" class="inputstyleBelow" id="email" value="E-mail Address" />
<span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
<span id="sprytextfield4">
<label for="text4"></label>
<input name="text4" type="text" class="inputrightBelow" id="sub" value="Message Subject" />
<span class="textfieldRequiredMsg"></span></span>
<span id="sprytextarea1">
<label for="textarea1"></label>
<textarea name="textarea1" cols="45" rows="5" class="inputstyleMsg" id="comments">Message Here</textarea>
<span id="countsprytextarea1"> </span><span class="textareaRequiredMsg"></span> <span class="textareaMinCharsMsg">Minimum number of characters not met.</span><span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span>
<div class="sendbtn"><input name="Submit message" type="submit" class="submitmail" value="" /></div>
</div>
</form>
</div>
</div>

Your form fields are incorrect. id is NOT used in form submission. the name parameter is. Since you've named your form fields as text1, text2, etc... but are looking for name1 and similar in your PHP code, you're trying to retrieve non-existent fields.
e.g. you have:
<input name="text1" type="text" class="inputstyle" id="name1" value="First Name" size="5" maxlength="5" />
$_POST['name1'];
no, that field will actually be $_POST['text1'].

Related

Form validation - required fields in php form

I've found a form that works well with multiple file uploads and am trying to work in some validation, i'm just trying to make some fields required for now.
Currently some validation is occuring with error messages however the form always posts regardless. My php knowledge is limited and it may look messy but I would be grateful if anybody could help me as to how to amend the following code..
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){
// we'll begin by assigning the To address and message subject
$to="paul#thedesignbank.co.uk";
$subject="Parts Request";
$subject = trim($_POST['namefrom']);
$vehiclereg = trim($_POST['vehiclereg']);
$chassisnumber = trim($_POST['chassisnumber']);
$contactnumber = trim($_POST['contactnumber']);
$emailfrom = trim($_POST['emailfrom']);
$address = trim($_POST['address']);
$town = trim($_POST['town']);
$postcode = trim($_POST['postcode']);
$comments = trim($_POST['comments']);
// get the sender's name and email address
// we'll just plug them a variable to be used later$from = stripslashes($_POST['fromname'])." <".stripslashes($_POST['fromemail']).">";
// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// here, we'll start the message body.
// this is the text that will be displayed
// in the e-mail
$message.="From: ".$subject."\n";
$message.="Email: ".$emailfrom."\n";
$message.="Vehicle Registration: ".$vehiclereg."\n";
$message.="Chassis Number: ".$chassisnumber."\n";
$message.="Address: ".$address."\n";
$message.="Town: ".$town."\n";
$message.="Postcode: ".$postcode."\n";
$message.="Contact Number: ".$contactnumber."\n";
$message.="Comment: ".$comments."\n\n";
//my validation gives a message but email still posts
$errors = array();
if (!$_POST['namefrom'])
// if not, add that error to our array
$errors[] = "Name is required";
// check to see if a subject was entered
if (!$_POST['emailfrom'])
// if not, add that error to our array
$errors[] = "Email Address is required";
if (!$_POST['contactnumber'])
// if not, add that error to our array
$errors[] = "Contact Number is required";
// check to see if a message was entered
if (!$_POST['vehiclereg'])
// if not, add that error to our array
$errors[] = "vehiclereg is required";
// if there are any errors, display them
if (count($errors)>0){
echo "<strong>ERROR:<br>\n";
foreach($errors as $err)
echo "$err<br>\n";
} else {
}
// next, we'll build the invisible portion of the message body
// note that we insert two dashes in front of the MIME boundary
// when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// now we'll process our uploaded files
foreach($_FILES as $userfile){
// store the file information to variables for easier access
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
// if the upload succeded, the file will exist
if (file_exists($tmp_name)){
// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){
// open the file for a binary read
$file = fopen($tmp_name,'rb');
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content.
// NOTE: we don't set another boundary to indicate that the end of the
// file has been reached here. we only want one boundary between each file
// we'll add the final one after the loop finishes.
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
// here's our closing mime boundary that indicates the last of the message
$message.="--{$mime_boundary}--\n";
// now we just send the message
if (#mail($to, $subject, $message, $headers))
echo "Message Sent Successfully";
else
echo "Failed to send";
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/form-data" name="form1">
<h3>Vehicle Details</h3>
<p style="margin:17px 0"> <label style=" font-family: Helvetica, Arial, sans-serif;">Vehicle Registration: <span style="color:red">*</span></label>
<input class="form-input" name="vehiclereg" id="vehiclereg" type="text" tabindex="1" style="width:100%;"/></p>
<p style="margin:17px 0"> <label style=" font-family: Helvetica, Arial, sans-serif;">VIN/Chassis Number (Last 6 Digits):</label>
<input class="form-input" name="chassisnumber" id="chassisnumber" type="text" tabindex="1" style="width:100%;"/></p>
<h3>Customer Details</h3>
<p style="margin:17px 0"> <label style=" font-family: Helvetica, Arial, sans-serif;">Name: <span style="color:red">*</span></label>
<input class="form-input" name="namefrom" id="namefrom" type="text" tabindex="1" style="width:100%;"/></p>
<!--changed these-->
<p style="margin:17px 0"><label style=" font-family: Helvetica, Arial, sans-serif;">Address:</label>
<input class="form-input" name="address" id="address" type="text" tabindex="1" style="width:100%;"/></p>
<p style="margin:17px 0"> <label style=" font-family: Helvetica, Arial, sans-serif;">Town:</label>
<input class="form-input" name="town" id="town" type="text" tabindex="1" style="width:100%;"/></p>
<p style="margin:17px 0"> <label style=" font-family: Helvetica, Arial, sans-serif;">Postcode:</label>
<input class="form-input" name="postcode" id="postcode" type="text" tabindex="1" style="width:100%;"/></p>
<!--changed these-->
<p style="margin:17px 0"> <label style=" font-family: Helvetica, Arial, sans-serif;">Email: <span style="color:red">*</span></label>
<input class="form-input" name="emailfrom" id="emailfrom" type="text" tabindex="3" style="width:100%;"/></p>
<p style="margin:17px 0"> <label style="margin-right: 4px; font-family: Helvetica, Arial, sans-serif;">Contact No: <span style="color:red">*</span></label>
<input type="text" class="form-input" name="contactnumber" id="contactnumber" rows="2" cols="22" tabindex="6" style="width:100%;" /></p>
<p style="margin:17px 0"> <label style="margin-right: 4px; vertical-align:top; font-family: Helvetica, Arial, sans-serif; ">Brief Description of Request: </label>
<textarea class="form-input" name="comments" id="comments" rows="7" cols="22" tabindex="6" style="height:50px; width:100%;" ></textarea></p>
<p style="margin:17px 0">
<label style="margin-right: 4px; font-family: Helvetica, Arial, sans-serif;">Vehicle image/doc one:</label>
<input type="file" name="file1">
</p>
<p style="margin:17px 0">
<label style="margin-right: 4px; font-family: Helvetica, Arial, sans-serif;">Vehicle image/doc two:</label>
<input type="file" name="file2">
</p>
<p style="margin:17px 0">
<label style="margin-right: 4px; font-family: Helvetica, Arial, sans-serif;">Vehicle image/doc three:</label>
<input type="file" name="file3">
</p>
<div style="clear:both">
<p> I would like to subscribe to the newsletter
<input name="subscribe" type="checkbox" value="website_subscribers" name="mailinglist[]" checked="checked" /></p>
</div>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
<?php } ?>
Using if (!$_POST['emailfrom']) will only check if the posted field exists. Regardless if it's empty or not.
Instead you could use empty:
if (empty($_POST['emailfrom'])) {
echo 'error'
}
You also can add some additional checks to the fields like a valid email check or phonenumber validator:
if (empty($_POST['emailfrom']) || !isValidEmailCustomFunction($_POST['emailfrom]')) {
echo 'error'
}
something like
if(!isset($_POST['namefrom']) || $_POST['namefrom']=="" ){
$error[]="Please enter your name";
}

PHP error on all fields required - but all fields are inserted

I'm making a signup form (signup.html) with a php handler (signup-form-handler.php).
But it seems like I'm doing something wrong.
This is my code:
$errors = '';
$myemail = 'example#domain.com';//<-----Put Your email address here.
if(empty($_POST['FirstName']) ||
empty($_POST['LastName']) ||
empty($_POST['City']) ||
empty($_POST['Country']))
{
$errors .= "\n Error: all fields are required";
}
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$City = $_POST['City'];
$Country = $_POST['Country'];
$Int1 = $_POST['Int1']; // <---- Here's what seems to be the issue
$Int2 = $_POST['Int2']; // <---- Here's what seems to be the issue
if( empty($errors))
{
$to = $myemail;
$email_subject = "Udfyldelse af test på Gamification: $FirstName";
$email_body = "Du har fået en ny besvarelse. ".
"Her er besvarelserne:\n Fornavn: $FirstName \n Efternavn: $LastName \n By: $City \n Land $Country \n".
"De fire personlige interesser: $Int1 og $Int2";
$headers = "From: $myemail\n";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
Here's the relevant html code:
<form id="contact_form" name="contact_form" action="signup-form-handler.php">
<!-- Personlige oplysninger -->
<div class="next">
<h3>Personlige oplysninger<a class="info" href="#" title="Testing"><img style="height: 15px; width: 15px; margin-left: 5px;" alt="Time" src="img/signup_form/info_simple.png"></a></h3>
<b>Mit navn er</b>
<input class="user_field" placeholder="fornavn" id="FirstName" name="FirstName" type="text" maxlength="60" />
<input class="user_field" placeholder="efternavn" id="LastName" name="LastName" type="text" maxlength="60" />
</br>
<b>og bor i</b>
<input class="user_field" placeholder="indsæt by" id="City" name="City" type="text" maxlength="60" />
<b>,</b>
<input class="user_field" placeholder="indsæt land" id="Country" name="Country" type="text" maxlength="60" />
</br>
</br>
<b>Beskriv dig selv med 4 interesser</b>
</br>
<input id="Int1" name="Int1" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 1" />
<input id="Int2" name="Int2" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 2" />
<input class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 3" />
<input class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 4" />
</div>
As you can see from my code example, I'm trying to get input from my an html form. I've commented in to the code, where the problem occurs. If I retrieve input from Int1 and Int2, I get the answer, that all required fields need to be filled in, but I don't want to require Int1 and Int2. Also I didn't add Int1 and Int2 in the beginning where I check if the other variables are empty.
If I remove Int1 and Int2 it all works fine.
When I send the form after inserting all the inputs, I get the following message:
"Error: all fields are required"
What am I doing wrong?
Hope I gave enough info to find the issue, thanks!
The default method is GET. Set your form method to POST:
<form id="contact_form" name="contact_form" action="signup-form-handler.php" method="POST">
So basically you're not passing the values to the script. If you wanted to use the GET method, switch all instances of $_POST to $_GET and you can leave your form as is.
In the inputs Int1 and Int2 the attribute type is missing.
ok, for starters, the "< b >" for bold tag is depricated, use "< strong > < /strong > "
if you add this to your php page it works, play about with the form though as i couldnt understand the danish to know what was what. this is a one page solution, no need for a HTML file
<?php
$form = '<form id="contact_form" name="contact_form" action="'.$_SERVER['PHP_SELF'].'" method="post" >
<!-- Personlige oplysninger -->
<h3>Personlige oplysninger<a class="info" href="#" title="Testing"><img style="height: 15px; width: 15px; margin-left: 5px;" alt="Time" src="img/signup_form/info_simple.png"></a></h3>
<strong>Mit navn er</strong>
<input class="user_field" placeholder="fornavn" id="FirstName" name="FirstName" type="text" maxlength="60">
<input class="user_field" placeholder="efternavn" id="LastName" name="LastName" type="text" maxlength="60" >
<input type="text" class="user_field" placeholder="fornavn" id="FirstName" name="FirstName" >
<strong>og bor i</strong>
<input class="user_field" placeholder="indsæt by" id="City" name="City" type="text" maxlength="60" >
<strong>,</strong>
<input class="user_field" placeholder="indsæt land" id="Country" name="Country" type="text" maxlength="60" >
<strong>Beskriv dig selv med 4 interesser</strong>
<input type="text" id="Int1" name="Int1" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 1" >
<input type="text" id="Int2" name="Int2" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 2" >
<input type="text" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 3" >
<input type="text" class="tag_btn user_field" style="color: #FFFFFF;" placeholder="Interesser 4" >
<input type="submit" name="submit" value="Enter">
</form>';
if (isset ($_POST['submit'])){
$errors = '';
$myemail = 'example#domain.com';//<-----Put Your email address here.
if(empty($_POST['FirstName']) ||
empty($_POST['LastName']) ||
empty($_POST['City']) ||
empty($_POST['Country']))
{
$errors .= "\n Error: all fields are required";
$display = $errors.$form;
}else{
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$City = $_POST['City'];
$Country = $_POST['Country'];
$Int1 = $_POST['Int1']; // <---- Here's what seems to be the issue
$Int2 = $_POST['Int2']; // <---- Here's what seems to be the issue
$to = $myemail;
$email_subject = "Udfyldelse af test på Gamification: $FirstName";
$email_body = "Du har fået en ny besvarelse. ".
"Her er besvarelserne:\n Fornavn: $FirstName \n Efternavn: $LastName \n By: $City \n Land $Country \n".
"De fire personlige interesser: $Int1 og $Int2";
$headers = "From: $myemail\n";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
}else{
$display = $errors.$form;
}
echo $display;
?>

intermittent duplicate emails from php contact form

First time posting here. I have a php contact form on a CMS site that is sending me duplicate emails. The problem is intermittent. Sometimes it send two copies, sometimes it sends as many as 8 copies. Sometimes it works normally. The issue started after removing some fields from the form.
The form submits to a separate page that sends the email to 3 recipients. This page also serves as a thank you page that displays the information submitted by the user. "Thanks for contacting us the following information has been received".
The embeds are expresionengine code. Thanks for your help!!!
Here is the form:
<form id="Form1" name="Form1" method="post" action="http://myprocessingpage.com">
<label for="fname">Name:</label> <input type="text" size="42" id="fname" name="fname"><br>
<label for="email">Email Address:</label> <input size="42" type="text" id="email" name="email"><br>
<label for="telephone">Telephone:</label> <input size="42" type="text" id="telephone" name="telephone"><br>
<br>
<div style="float: left; margin-right: 20px; margin-bottom: 30px;">
<label>How did you hear about us?</label> <br>
<input type="hidden" id="arrayfix" name="how[]" value="">
<input type="checkbox" id="website" name="how[]" value="website"> Website<br>
<input type="checkbox" id="referral" name="how[]" value="referral"> Referral<br>
<input type="checkbox" id="tradeshow" name="how[]" value="tradeshow"> Tradeshow<br>
</div>
<div style="float: left; margin-bottom: 30px;">
<label >Shelter Type:</label><br>
<input type="hidden" id="arrayfix2" name="type[]" value="">
<input type="checkbox" id="safe4x6" name="type[]" value="Safe_Room_4X6"> 4'X6' Shelter<br>
<input type="checkbox" id="safe4x8" name="type[]" value="Safe_Room_4X8"> 4'X8' Shelter<br>
<input type="checkbox" id="custom" name="type[]" value="Custom_Size_Safe_Room"> Custom Size Shelter<br>
</div>
<div style="clear: both;"></div>
<label for="question"> Questions or Comments:</label><br> <textarea rows="7" maxlength="500" name="question" id="question" cols="50"></textarea><br>
<br>
<input type="submit" class="btnimage" id="submit" name="submit" value="">
</form>
Here is the processing page (http://myprocessingpage.com):
<?php
if (isset($_POST['fname']))
{
?>
<!DOCTYPE html>
<head>
<title>Thank you for contacting us!</title>
{embed="page/headtags"}
</head>
<body>
{embed="page/header"}
{embed="page/drop"}
<div id="contentbg">
<div id="content">
<?php
$name = $_POST['fname'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$question = $_POST['question'];
$howarray = $_POST['how'];
$howimplode = implode("\n", $howarray);
$how = str_replace("_", " ", "$howimplode");
$typearray = $_POST['type'];
$typeimplode = implode("\n", $typearray);
$type = str_replace("_", " ", "$typeimplode");
//sent to us
$to = "mail1#mail.com, mail2#mail.com, mail3#mail.com";
$subject = "Info Request";
$message = "INFO REQUEST:\n\nName: $name\n\nEmail: $email\n\nTelephone: $telephone\n\nHow they heard about us:\n$how\n\nShelter type:\n$type\n\nQuestions or Comments:\n$question";
$from = "info#mysite.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>
<div id="form">
<p style="margin-top: 0px; margin-bottom: 40px; color: green; font-weight: bold;">Thank you for contacting us! The following information has been received:</p>
<div style="margin-left: 30px;">
<?php
echo "<p><b>Name:</b> ".$name."</p>";
echo "<p><b>Email:</b> ".$email."</p>";
echo "<p><b>Telephone:</b> ".$telephone."</p>";
$thankshowimplode = implode("</br>", $howarray);
$thankshow = str_replace("_", " ", "$thankshowimplode");
$thankstypeimplode = implode("</br>", $typearray);
$thankstype = str_replace("_", " ", "$thankstypeimplode");
echo "<p><b>How you heard about us:</b></br> ".$thankshow."</p>";
echo "<p><b>Type of shelter(s):</b></br> ".$thankstype."</p>";
echo "<p style='word-wrap:break-word;'><b>Questions or Comments:</b> ".$question."</p>";
?>
</div>
</div>
</div>
{embed="page/footer"}
</body>
</html>
<?php
}
else
{
?>
<script type="text/javascript">
window.location = 'http://mycontactpage.com';
</script>
<?php
}
?>
If someone double-clicks (or clicks it 8 times) your submit button, your script could be run more than once. Try disabling the submit button on click (using Javascript).
Another, probably unnecessary, solution would be to lock your form script (e.g. using semaphores), create a database entry with the provided info, then check to see if you've sent the same info recently (e.g. within the last five minutes), and don't sent it again if you have.
I'm sure the Javscript disable functionality will suffice :)
Or, if you want to find out what's really going on, you could just create a log file that logs "sent [some distinct piece of data that might tell these posts apart] at [timestamp]". If you see a couple of these, with the same [distinct info] entry and really close timestamp, then your problem is multiple clicks to the submit button.

Send.php not showing content of the forms

so i finally got my feedback form to be working and sending emails to my email address but i have another problem. The content of the forms are not showing, don't know what is wrong. I'm new to php tho so i'm very sure its simple.. posted the code below
<?php
$name = $_POST ['name'];
$mail = $_POST ['mail'];
$number = $_POST ['number'];
$feedback = $_POST ['feedback'];
$to = 'ATotallyRandom#Email.net';
$subject = 'Feedback from atetaconsult.com';
$msg = "Your name: $name\n" .
" Your email: $email\n" .
" Feedback: $feedback\n";
mail ($to, $subject, $msg, 'From:' . $email);
echo ' thank you <br/>';
echo ' your name ' .$name .'<br/>';
echo ' Your email ' . $email .'<br/>';
echo ' Your feedback ' . $feedback . '<br/>';
?>
The HTML code for the form is below too
<form method="post" action="send.php">
<p class="head" style="font-style: italic; color: #fff; line-height: 24px; font-size: 19px; margin-bottom: 47px; margin-top: 20px; font-family: Lato, sans-serif;">
We’d love to hear from you. Interested in working together? Fill out the form below with some info about your project and I will get back to you as soon as I can. Please allow a couple days for me to respond.</p>
<div class="row form">
<input id="name" class="name" type="text" placeholder="Name">
<input id="mail" class="mail" type="text" placeholder="Email">
<input id="number" class="phone" type="text" placeholder="Phone">
</div>
<div class="span6 box box_r">
<textarea id="feedback" rows="6" class="span6" placeholder="Type a message here..."></textarea>
</div>
<div class="btn" style="margin-top:5px;">
<input type="submit" value="Send your message">
</div>
</form><div style="clear: both;"></div>
Here:
$msg = "Your name: $name\n" .
" Your email: $email\n" .
" Feedback: $feedback\n";
you are asking for the variable $email
but you have specified it as $mail at the top.
See: http://markpetherbridge.co.uk/StackOverflow/phpmail.php?name=Mark&mail=test#test.com&feedback=testfeedback
I have changed it to $email and the type to $_GET for demonstration purposes, but it seems to be working. Try that.
Here is the Full code for the file:
<?php
$name = $_GET ['name'];
$email = $_GET ['mail'];
$number = $_GET ['number'];
$feedback = $_GET ['feedback'];
$to = 'ATotallyRandom#Email.net';
$subject = 'Test from Mark P';
$msg = "Your name: $name\n";
$msg .= " Your email: $email\n";
$msg .= " Feedback: $feedback\n";
mail ($to, $subject, $msg, 'From:' . $email);
echo ' thank you <br/>';
echo ' your name ' .$name .'<br/>';
echo ' Your email ' . $email .'<br/>';
echo ' Your feedback ' . $feedback . '<br/>';
?>
<br /><br />
Here is the result from $msg: <br /><br />
<?php
echo $msg;
?>
You need to add name into your html:
<input name="name" id="name" class="name" type="text" placeholder="Name">
<input name="mail" id="mail" class="mail" type="text" placeholder="Email">
<input name="number" id="number" class="phone" type="text" placeholder="Phone">
Put all these code in between:
if($_POST){
// Your coding
}
Also show me the Javascript/Jquery coding you are using on contact form.
You haven't set a name value on the input.
Change in:
<form method="post" action="send.php">
<p class="head" style="font-style: italic; color: #fff; line-height: 24px; font-size: 19px; margin-bottom: 47px; margin-top: 20px; font-family: Lato, sans-serif;">
We’d love to hear from you. Interested in working together? Fill out the form below with some info about your project and I will get back to you as soon as I can. Please allow a couple days for me to respond.</p>
<div class="row form">
<input name="name" id="name" class="name" type="text" placeholder="Name">
<input name="mail" id="mail" class="mail" type="text" placeholder="Email">
<input name="number" id="number" class="phone" type="text" placeholder="Phone">
</div>
<div class="span6 box box_r">
<textarea name="feedback" id="feedback" rows="6" class="span6" placeholder="Type a message here..."></textarea>
</div>
<div class="btn" style="margin-top:5px;">
<input type="submit" value="Send your message">
</div>
</form><div style="clear: both;"></div>

Wordpress giving me a 404 error for php form

Since the Wordpress form seems to not want to send me the password to my account for help on their forums I figured I would start here.
I have created a form for my website so that someone can contact us.
But when the person clicks the 'send' button it takes them to a 404 page, which the address reads:
website address - /working/mail.php
I know Wordpress supports .php files and I have mine correctly named and wasn't sure if I am missing something
<div id="FGSform">
<form action="mail.php" method="post" name="contactFGS" id="contactFGS">
<ul>
<li>
<label for="first-name">First Name</label>
<br>
<input type="text" id="firstname" name="firstname" required aria-required="true">
</li>
<br>
<li>
<label for="last-name">Last Name</label><br>
<input type="text" id="lastname" name="lastname" required aria-required="true">
</li>
<br>
<li>
<label for="email">Email</label>
<br>
<input type="email" id="email" name="email" required aria-required="true">
</li>
<br>
<li>
<label for="contact-reason" id="reason" name="reason">Reason for Contact</label>
<select required id="reason" name="reason">
<option value="3">Employment</option>
<option value="1">Print Services</option>
<option value="2">Design Services</option>
<option value="4">Questions</option>
<option value="5">Other</option>
</select>
</li>
<br>
<li>
<label for="comments">Comments</label>
<br>
<textarea name="comments" id="comments" cols="40" rows="10" required></textarea>
</li>
<br>
<li>
<input type="radio" id="newsletter" name="newsletter">
<label for="signmeup">Sign me up for newsletter, updates and other information about FGS</label>
</li>
<br>
<li>
<input type="submit" value="Send">
</li>
Here is my .php file:
<?php
/* Email Variables */
$emailSubject = 'mail!';
$webMaster = 'kmurray.1#frgraphicsolutions.com';
/* Data Variables */
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$email = $_POST['email'];
$body = <<<EOD
<br><hr><br>
Name: $name <br>
Last Name: $lastname <br>
Email: $email <br>
Comments: $comments <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);
/* Results rendered as HTML */
$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="3;URL=http://frgraphicsolutions.com/working/?page_id=8">
<style type="text/css">
<!--
body {
background-color: #444;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #fec001;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}
-->
</style>
</head>
<div align="center">Thank you!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>
I have never created a form before, but Wordpress plug-ins are terrible designed and/or over complicate the form giving me little control over what I want in it.
Any help is much appreciated.
I cannot post comments yet or I would add this as a comment but it seems there is no mail.php file. Can you check the full path to the file? It's not in / or in /working/.
Edit in response to your comment:
You should try two things in that order:
Output the result of the form just to check that you are reaching
the form processing file and that everything is working on that
side.
Send an email to yourself using basic parameters, in a file with no
link with the form. This way you'll know if you are able to send
emails properly and you'll be closer to a solution.
Let us know what you find.
After time spent with the OP to find out what the problem was, have determined the following solution:
Set your your form action to this
<form action="/working/wp-content/themes/NEW/mail.php" method="post" name="contactFGS" id="contactFGS">
Since the mail.php file (handler) was inside a themes folder, and not as previously thought.
Change the path in the form tag to /mail.php or whatever is the url of mail.php
EDIT:
Incase it's not clear, just change the form action to the url of your mail.php..

Categories