Internal Server Error With Minimal PHP Contact Form - php

This site is hosted on shared hosting, unfortunately, the only thing the host seems to make available is the access log, not the PHP error log, so I'm having trouble figuring out the specific error here.
I'm trying to do a very minimal, simple contact form in PHP, without much validation or complexity. Getting a 500 error, though I'm sure I'm overlooking something basic.
Any assistance greatly appreciated.
HTML:
<form name="htmlform" method="post" action="collins_contact.php">
<table width="450px" cellpadding="20px">
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="first_name">First Name</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="last_name">Last Name</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="email">Email Address</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="telephone">Telephone</label>
</td>
<td valign="top">
<input type="text" name="phone" maxlength="30" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="comments">Questions / Comments</label>
</td>
<td valign="top">
<textarea name="message" maxlength="1000" cols="25" rows="6"></textarea>
</td>
<tr><td> </td></tr>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
</td>
</tr>
<tr><td> </td></tr>
</table>
</form>
PHP
<?php
if (isset($_POST["first_name"]) && isset($_POST["email"]) && isset($_POST["message"])) {
$name = $_POST["first_name"];
$email = $_POST["email"];
$subject = "Contact Form Submission";
$message = $_POST["message"];
$header = "from: $name <$email>";
$to = "contact#domain.com";
if (mail($to, $subject, $message, $header)) {
header("Location: index.html");
} else {
echo("Error With Form Submission");
}
}
?>

Permissions needed to be changed to 0644 on the php file, then it worked.

Related

when press submit the page reloading as the php file

I have some problem with my form...
When I press the submit button the page not only doesn't send the mail, it also reloading the page and show the php file at a text all over the website... Someone know how to fix that please?
Thank you all!
The form part from the HTML:
<form action="mail.php" method="post">
<table class="table">
<tbody>
<tr>
<td rowspan="2" width="50%">
<div class="cart-total">
<strong class="cart-total-title">סך הכל</strong>
<span class="cart-total-price">0₪</span>
</div>
</td>
<td align="right" width="25%">
<input type="text" name="inpPhone" size="10" required></input>
:טלפון
</td>
<td align="right" width="25%">
<input type="text" name="inpName" size="10" required></input>
:שם מלא
</td>
</tr>
<tr>
<td align="right" width="25%">
<input type="text" name="inpCity" size="10" required></input>
:עיר
</td>
<td align="right" width="25%">
<input type="text" name="inpAddress" size="10" required></input>
:כתובת
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="date" name="inpDate" required></input>
:תאריך אספקה (ניתן להזמין עד יומיים לפני)
</td>
</tr>
<tr>
<td colspan="3" align="right">
</br>
אם הוזמנו מארז עוגיות/עוגת שמרים, יווצר עמך קשר בהמשך לגבי בחירת עוגיות/עוגה *
</td>
</tr>
</tbody>
</table>
<input type="submit" class="btn btn-primary btn-purchase" name="submit">להזמנה</button>
</form>
PHP:
<?php
if (isset(_POST['submit'])) {
$subject = "הזמנה חדשה";
$name = $_POST['inpName'];
$phone = $_POST['inpPhone'];
$city = $_POST['inpCity'];
$address = $_POST['inpAddress'];
$mailTo = "sappati#outlook.com";
$headers = "From:".$name;
$txt =
"התקבלה הזמנה חדשה! אלו פרטי ההזמנה:\n".
"שם: ".$name."\n".
"טלפון: ".$phone."\n".
"עיר: ".$city."\n".
"כתובת: ".$address."\n";
mail($mailTo, $subject, $txt, $headers);
}
?>
It's the native behavior of server side languages to reload to handle the request, if you want to make requests to server side, then you should use XMLHttpRequest or fetch or any other library for making requests
And about the php file being served as text, you should have apache or any other server install on your local machine to be able to handle server side code

ReCaptcha V2 returns False even though checked

Having a problem with ReCaptcha. Even if checkbox is checked, it still returns false. I have triple checked my keys and happy they are correct. I am using code based on that successfully used on another of my sites. Cannot see what is wrong.
For ease of reference, I have copied all the relevant coding. Hopefully someone will see straight away what I've done wrong.
Form Code:
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" placeholder="Please enter your first name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" placeholder="Please enter your surname" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="email" name="email" placeholder="Please enter your email address" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="tel" name="telephone" placeholder="Please enter your phone number" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><div class="g-recaptcha" data-sitekey="6LejdlwUAAAAAHb5qaNIhfDzxL1i9a9sCyw8dLzD"></div></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> <br> Email Form
</td>
</tr>
</table>
</form>
Code from the PHP:
<?php
// Code from ReCaptcha evaluation:
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['comment'])){
$email=$_POST['comment'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "************************************";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are a spammer ! Your form has been rejected.</h2>';
} else
// End Code from ReCaptcha evaluation.
Many Thanks
Tim

contact form not work in include function in php [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am including my contact form in index.php
in index.php
left.php code is
html code
<form action="" enctype="multipart/form-data" method="post">
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" hspace="0" vspace="0" width="100%">
<tbody>
<tr>
<td class="fth" height="20" valign="middle"></td>
</tr>
<tr>
<td class="ft">* Name:</td>
</tr>
<tr>
<td class="ft"><input name="author" id="name" class="text" required="true" valtype="name" type="text" maxlength="25" placeholder="Enter Your Full Name" pattern="^[a-zA-Z -]+$"></td>
</tr>
<tr>
<td class="ft">* Phone:</td>
</tr>
<tr>
<td align="left" valign="top" class="ft">
<input name="mobile" id="phone" class="text" size="20" valtype="phmob" required="true" type="text" maxlength="12" placeholder="Enter 10 Digit Mobile Number" pattern="[789][0-9]{9}">
<span class="style3">eg : 9795042637</span></td>
</tr>
<tr>
<td class="ft">* E-mail:</td>
</tr>
<tr>
<td class="ft">
<input name="email" id="email" class="text" valtype="email" required="true" type="text" maxlength="55" pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$" placeholder="Enter Your Email Address">
</td>
</tr>
<tr>
<td class="ft">*Write your message:</td>
</tr>
<tr>
<td class="ft">
<textarea name="msg" id="msg" cols="25" rows="3" class="text" valtype="msg" nameinerr="Message" required="true" onkeypress="return preventCopy.disableCtrlKeyCombination(event, this);" onkeydown="return preventCopy.disableCtrlKeyCombination(event, this);" oncontextmenu="return false;" onmousedown="return preventCopy.rightClick(event,this);"></textarea>
</td>
</tr>
<tr>
<td class="ft">
<label for="home_loan"><input id="home_loan" class="home_loan" name="home_loan" value="Yes" type="checkbox">I am interested in Home Loan</label>
</td>
</tr>
<tr>
<td class="ft" height="45">
<br>
<input class="submit" value="Send" type="submit" name="button">
<input class="submit" type="reset" name="reset" id="reset" value="Reset" />
</td>
</tr>
</tbody></table>
</div>
php code in same file
if(isset($_POST['button']))
{
ob_start();
$name=$_POST['author'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$msg=$_POST['msg'];
$home_loan=$_POST['home_loan'];
$to ='mysite#gmail.com';
//$to ='info#mysite.in';
$subject = 'Enquiry Through mysite HomePage';
$message ="
Name = $name\r\n
E-mail = $email\r\n
Mobile = $mobile\r\n
Message = $msg\r\n
Home loan = $home_loan";
$headers = "From: $name < $email >" . "\r\n" .
"CC:mysite#gmail.com";
$sendmail = mail($to,$subject,$message,$headers,"-from#mysite.com");
if($sendmail)
{
//header("location:thanks.html");
echo "<h4 style='text-align:center;color:red;'>Your enquiry has been sent.</h4>";
}
else
{
header("location:index.php");
}
}
It is working fine when running mysite.com/left.php
but when I use in include its not submit query where am wrong help me out
thanks
Try changing your form declaration from this:
<form action="" enctype="multipart/form-data" method="post">
to this:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data" method="post">
Move the php code to the top of index.php. You're doing things before anything should be outputted. If index.php outputs anything before this runs, it fails.

Having trouble sending HTML form to email through PhP [duplicate]

This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 7 years ago.
I have created a form and would like the information to be sent to my email using php. The information submits, and I receive an e-mail, but the email only displays the first and last name of input by the individual submitting the form. I would like to know what is missing from either the php side or html side.
Thank You
<form name="contactform" method="post" action="appraisal_form.php">
<table width="500px">
<tr>
<td>
<label for="first_name">First Name *</label>
</td>
<td>
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="last_name">Last Name *</label>
</td>
<td>
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="email">Email Address *</label>
</td>
<td>
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="telephone">Telephone Number</label>
</td>
<td>
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<!--- Property Type-->
<tr>
<td>
<label for="lender">Lender *</label>
</td>
<td>
<input type="text" name="lender" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_officer">Loan Officer *</label>
</td>
<td>
<input type="text" name="loan_officer" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="property_address">Email Address *</label>
</td>
<td>
<input type="text" name="property_address" maxlength="100" size="30">
</td>
</tr>
<tr>
<td>
<label for="city">City *</label>
</td>
<td>
<input type="text" name="city" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="zip">Zip Code *</label>
</td>
<td>
<input type="text" name="zip" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="pin">PIN(Permenant Index Number) *</label>
</td>
<td>
<input type="text" name="pin" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="rooms">Number of Rooms *</label>
</td>
<td>
<input type="text" name="rooms" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="bath">Number of Bathrooms *</label>
</td>
<td>
<input type="text" name="bath" maxlength="80" size="30">
</td>
</tr>
<!--- Garage /yes or no-->
<tr>
<td>
<label for="plat">Plat of Survey *</label>
</td>
<td>
<input type="text" name="plat" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="borrow">Borrowers Name *</label>
</td>
<td>
<input type="text" name="borrow" maxlength="80" size="30">
</td>
</tr>
<!--- sale /refinance-->
<tr>
<td>
<label for="price">Purchase Price *</label>
</td>
<td>
<input type="text" name="price" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_amount">Loan Amount *</label>
</td>
<td>
<input type="text" name="loan" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="cod">C.O.D *</label>
</td>
<td>
<input type="text" name="cod" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="invoice">Invoice *</label>
</td>
<td>
<input type="text" name="invoice" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="comments">Comments *</label>
</td>
<td>
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" name="submit" id="submit" value="Submit">
<input type="reset" name="Reset" id="reset" value="reset">
</td>
</tr>
</table>
</form>
PHP
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$lender = $_POST['lender']; // required
$loan_officer = $_POST['loan_officer']; // required
$property_address = $_POST['property_address']; // required
$city = $_POST['city']; // required
$zip = $_POST['zip']; // not required
$pin = $_POST['pin']; // required
$rooms = $_POST['rooms']; // required
$bath = $_POST['bath']; // required
$plat = $_POST['plat']; // required
$borrow = $_POST['borrow']; // not required
$price = $_POST['price']; // required
$cod = $_POST['cod']; // not required
$comments = $_POST['comments']; // required
$to = "rosaliam2#yahoo.com";
$subject = "New Appraisal Request";
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid. <br />';
}
mail($to, $subject, $message, "From" . $first_name . $last_name);
echo "Your Information has been sent";
?>
Actually there is no message variable to send!!
you are just sending $first_name and $last_name as headers!

Error Placing on same page PHP

some of my code in addUser.php it pure html
addUser.php
<form action="process/addNewUser.php" method="POST" id="userForm">
<table width="79%" border="0" cellspacing="6" cellpadding="1"
class="tabcont">
<tr>
<td width="47%" align="right">Title:</td>
<td width="53%">
<select name="title"><option value='0'>- - select - -</option>
</select>
</td>
</tr>
<tr>
<td width="47%" align="right">
First Name:</td>
<td width="53%"><input type="text" id="firstname" name="firstName" class="required" /></td>
</tr>
<tr>
<td align="right">Middle Name:</td>
<td><input type="text" id="middlename" name="middleName" class="name" /></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input name="password" value="" readonly="readonly"
id="password" class="required" " /></td>
</tr>
<tr>
<td align="right" colspan="2">
<input name="addNewUser" type="submit" class="submit" id="submit" value="Submit" />
</td>
</tr>
</table>
</form>
addNewUser.php
Here i am doing validations and displaying error messages and if it is success sending him to another page.
But i want to show an error message on addUser.php instead of validations page. Please give me a sample code how i can do it.
addNewUser.php
Add the message in the session
$_SESSION["ErrorMsg"]="Name already exists";
And in your addUser.php , you put the following code in the place you need to show the msg :
if($_SESSION["ErrorMsg"])
{
echo $_SESSION["ErrorMsg"];
$_SESSION["ErrorMsg"]="";
}

Categories