php mail form doesn't send mail - php

I seem to have a problem with an email form I am making.
the form worked correctly until I added some extra parts to it. however, even when I comment my changes, it won't work.
I thought the problem might be due to some syntax error, but It doesn't seem to be so.
I do not get any error message
below is my code:
<?php
if(isset($_REQUEST['email'])) {
$num=$_REQUEST['num'];
$desc=$_REQUEST['desc'];
$subject="einak";
$nomr=$_REQUEST['nomr'];
$sphr=$_REQUEST['sphr'];
$cylr=$_REQUEST['cylr'];
$angr=$_REQUEST['angr'];
$addr=$_REQUEST['addr'];
$diar=$_REQUEST['diar'];
$noml=$_REQUEST['noml'];
$sphl=$_REQUEST['sphl'];
$cyll=$_REQUEST['cyll'];
$angl=$_REQUEST['angl'];
$addl=$_REQUEST['addl'];
$dial=$_REQUEST['dial'];
$type=$_REQUEST['type'];
$matter=$_REQUEST['matter'];
$color=$_REQUEST['color'];
$message=$num."<br />".$nomr."<br/>".$sphr."<br/>".$cylr."<br/>".$angr."<br />".$addr."<br />".$diar."<br />"."<br />".$noml."<br/>".$sphl."<br/>".$cyll."<br/>".$angl."<br />".$addl."<br />".$dial."<br />".$desc."<br />".$type."<br />".$matter."<br />".$color."<br />";
$email='info#toosoptic.ir';
$headers='MIME-Version: 1.0'."\r\n";
$headers.='Content-type: text/html; charset=iso-8859-1'."\r\n";
mail("mail#example.com",$subject,$message,$headers);
echo "ارسال شما موفقیت آمیز بود";
} else {
echo "<form method='post'>
<input name='num' id='num' type='text' /> <br />
<input type='text' name='nomr' id='nomr' > <br />
<input type='text' name='sphr' id='sphr'> <br />
<input type='text' name='cylr' id='cylr' > <br />
<input type='text' name='angr' id='angr' > <br />
<input type='text' name='addr' id='addr' > <br />
<input type='text' name='diar' id='diar' > <br />
<input type='text' name='noml' id='noml' > <br />
<input type='text' name='sphl' id='sphl'> <br />
<input type='text' name='cyll' id='cyll' > <br />
<input type='text' name='angl' id='angl' > <br />
<input type='text' name='addl' id='addl' > <br />
<input type='text' name='dial' id='dial' > <br />
<textarea id='desc' name='desc'> </textarea>
<input name='type' type='radio' value='bifocal' id='type1' />
<input name='type' type='radio' value='progres' id='type2' />
<input name='type' type='radio' value='single' id='type3' />
<input name='type' type='radio' value='decen' id='type4' />
<input name='matter' type='radio' value='glass' id='mat1' />
<input name='matter' type='radio' value='plastic' id='mat2' />
<input name='color' type='radio' value='single' id='col1' />
<input name='color' type='radio' value='decen' id='col2' />
<input type='submit' id='sb' value='ارسال اطلاعات' />
<input type='text' name='name' id='name' > <br />
<input type='add' name='address' id='address' > <br />
</form >
<p id='confirmation'></p>
<input type='submit' id='vis' onClick='vis(); return false;' value='تایید اطلاعات'/>";
}
?>

You have not define the name in the submit button here:
<input type='submit' id='sb' value='ارسال اطلاعات' />
Replace above code with the below code:
<input type='submit' id='sb' name='email' value='ارسال اطلاعات' />
You are checking the code if(isset($_REQUEST['email'])) and there is no email field the form as I see.
Basically this check is used for verifying that form have submitted or not(as generally other do). So you need to add the name='email' in the submit button attribute to execute the if condition code..

You're setting a mime header but you're not setting any mime encoding, that might be one issue ;-)
Try using a dedicated package such as PEAR/Mail (and PEAR/Mail/Mime) or phpMailer.

Related

Storing customisable quiz questions and answers in a .txt file using PHP

I have a customisable quiz site, where the user can input questions and answers. My first PHP file takes the inputted information and generates a quiz page. The answers are in hidden text box. A second PHP then compares the inputted radio button to the hidden text box to see if the user is correct and gives a score in relation to that. I would like to store the questions and answers in a .txt file which could then be accessed by other users, unfortunately as part of the project we are not able to use MySQL. Hopefully I am being clear, I have tried to go about this many ways but all have broken my code. Any ideas would be much appreciated.
My code is below:
INITIAL HTML:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="actions.php" method="post">
<strong>Question 1:</strong> <input name="q1" type="text" /> <br />
Answer 1: <br />
<input name="a11" type="text" /><input name="1" type="radio" value="1.1" /><br />
Answer 2: <br />
<input name="a12" type="text" /><input name="1" type="radio" value="1.2" /><br />
Answer 3: <br />
<input name="a13" type="text" /><input name="1"type="radio" value="1.3" /><br />
Answer 4: <br />
<input name="a14" type="text" /><input name="1" type="radio" value="1.4" />
<br /><br />
<strong>Question 2:</strong> <input name="q2" type="text" /> <br />
Answer 1: <br />
<input name="a21" type="text" /><input name="2" type="radio" value="2.1" /><br />
Answer 2: <br />
<input name="a22" type="text" /><input name="2" type="radio" value="2.2" /><br />
Answer 3: <br />
<input name="a23" type="text" /><input name="2"type="radio" value="2.3" /><br />
Answer 4: <br />
<input name="a24" type="text" /><input name="2" type="radio" value="2.4" />
<br /><br />
<strong>Question 3:</strong> <input name="q3" type="text" /> <br />
Answer 1: <br />
<input name="a31" type="text" /><input name="3" type="radio" value="3.1" /><br />
Answer 2: <br />
<input name="a32" type="text" /><input name="3" type="radio" value="3.2" /><br />
Answer 3: <br />
<input name="a33" type="text" /><input name="3"type="radio" value="3.3" /><br />
Answer 4: <br />
<input name="a34" type="text" /><input name="3" type="radio" value="3.4" />
<input name="" type="submit" />
</form>
</body>
FIRST PHP:
<html>
<body>
<form action="actions2.php" method="post">
<strong><?php echo $_POST["q1"];?></strong>
<br /><br />
<?php
echo $_POST["a11"]."<input name='newa1' type='radio' value='1.1' />"."<br />".$_POST["a12"]."<input name='newa1' type='radio' value='1.2' />"."<br />".$_POST["a13"]."<input name='newa1' type='radio' value='1.3' />"."<br />".$_POST["a14"]."<input name='newa1' type='radio' value='1.4' />"."<br />";
echo "<br /><br />"
?>
<strong><?php echo $_POST["q2"];?></strong>
<br><br>
<?php
echo $_POST["a21"]."<input name='newa2' type='radio' value='2.1' />"."<br />".$_POST["a22"]."<input name='newa2' type='radio' value='2.2' />"."<br />".$_POST["a23"]."<input name='newa2' type='radio' value='2.3' />"."<br />".$_POST["a24"]."<input name='newa2' type='radio' value='2.4' />"."<br />";
echo "<br /><br />"
?>
<strong><?php echo $_POST["q3"];?></strong>
<br><br>
<?php
echo $_POST["a31"]."<input name='newa3' type='radio' value='3.1' />"."<br />".$_POST["a32"]."<input name='newa3' type='radio' value='3.2' />"."<br />".$_POST["a33"]."<input name='newa3' type='radio' value='3.3' />"."<br />".$_POST["a34"]."<input name='newa3' type='radio' value='3.4' />"."<br />";
echo "<br /><br />"
?>
<input name="result1" type="hidden" value="<?php echo $_POST['1']; ?>">
<input name="result2" type="hidden" value="<?php echo $_POST['2']; ?>">
<input name="result3" type="hidden" value="<?php echo $_POST['3']; ?>">
<input name="" type="submit" />
</form>
<br /><br />
</body>
</html>
SECOND PHP:
<?php
$correctAnswer1 = $_POST['result1'];
$newAnswer1 = $_POST['newa1'];
$correctAnswer2 = $_POST['result2'];
$newAnswer2 = $_POST['newa2'];
$correctAnswer3 = $_POST['result3'];
$newAnswer3 = $_POST['newa3'];
$score = 0;
if($newAnswer1 == $correctAnswer1) {
$score++;
}
if($newAnswer2 == $correctAnswer2) {
$score++;
}
if($newAnswer3 == $correctAnswer3) {
$score++;
}
if ($score >= 2)
{
echo "Congratulations, you did well. You got ".$score;
}
else if ($score == 1)
{
echo "Only one, poor show";
}
else
{
echo "YOU GOT ZERO YOU SHITE";
}
?>
I'm not totally sure what you wanted, but if you need a way to store the questions and answers you could look into XML or JSON.
PHP should have libraries to encode/decode both of them
I am not sure if I have understood the question pretty well, but this is how you store in a .txt file using php.
http://bd1.php.net/file_put_contents also take a look at this http://www.w3schools.com/php/func_filesystem_fwrite.asp

Post values to form fields?

I have a form for adding products and their detail to a mysql db.
I have another form that shows the products where I can remove the product from the db, I can also hide or show the product in the website.
I need to be able to edite the product details too. Is there any way that when I choose to edit a products I can get it details to appear in the first form again? The form is for adding details so can it be used to edit them too?
This is my code for first product adding form.
<form class='productsaddform' action='productsadd.php' method='post'
enctype='multipart/form-data' name='image_upload_form' id='image_upload_form'>
<?php
include '../inc/categorydropdown.php';?>
<p><b>Choose Image</b><br /><input name="image_upload_box" type="file"
id="image_upload_box" /></p>
<b>Name</b><br /><input type=text name="aname" /><br />
<b>Brand</b><br /><input type=text name="abrand" /><br />
<b>Code</b><br /><input type=text name="acode" /><br />
<b>Description</b><br /><textarea rows="12" cols="40" name="adescription"></textarea>
<br />
<b>Product Spec</b><br /><textarea rows="12" cols="40" name="aspec"></textarea><br />
<b>Price</b><br /><input type=text name="aprice" /><br />
<p><label for="cat">Category</label>
<select name="cat" id="cat">
<?php echo $op;?>
</select><br />
<label for="subcat">Subcategory</label>
<select name="subcat" id="subcat"> </select></p>
<br />
<br />
<input type='submit' id='submit' name='submit' value='Add Product' />
<input type='hidden' value='new' /><br />
<?php include '../inc/add_products.php'; ?>
</form>
And this is the form to display the products
<form class='productsremoveform' action='productsadd.php' method='post'>
<?php include '../inc/categorydropdown.php'; ?>
<?php include '../inc/remove_products.php'; ?>
<span class='formheading'>Remove/Hide/Show Products</span><br /><br />
<p><label for="cat">Category</label>
<select name="cat" id="removecat"> <?php echo $op;?> </select><br />
<label for="subcat">Subcategory</label>
<select name="subcat" id="removesubcat"> </select>
<input type='submit' name='show' value='Show' /> </p>
<?php
include '../inc/connect.php';
if(isset($_POST['show'])){
$subcat = intval($_POST['subcat']);
$q = "SELECT * FROM products WHERE subcat = $subcat";
$result = $link->query($q);
if($result){
while($row=mysqli_fetch_array($result)){
echo "<div class='removeproducts'>";
echo "<input type='checkbox' name='remove[{$row['id']}]' value='Remove'>Remove";
echo "<br />";
echo "<input type='checkbox' name='edit[{$row['id']}]' value='Edit'>Edit";
echo "<br />";
if ($row['status'] == 1){
echo"<input type='checkbox' name='hide[{$row['id']}]' value='Hide'>Hide";
echo "<br />";
}
if ($row['status'] == 2){
echo"<input type='checkbox' name='show[{$row['id']}]' value='Show'>Show";
echo "<br />";
}
echo "<br />",
"<span class='productthumbcode'>",
"{$row['code']}",
"</span>",
"<div id='thumb'>",
"<img class='resizedimage' src='{$row['image']}' alt='{$row['name']}' />",
"</div>",
"</div>";
}
echo "<br style='clear:both' />";
}
else{
echo mysqli_error();
}
}
?>
<input type='submit' id='submit' name='submit' value='Submit' />
</form>
EDIT;
This is the form on my new edit page.How do i get the relevent details from the db into the input values?
<?php if (isset($_GET['pid'])) { ?>
<form class='productsaddform' action='edit_products.php' method='post'
enctype='multipart/form-data' name='image_upload_form' id='image_upload_form'>
<span class='formheading'>Edit Product</span><br /><br />
<p><b>Choose Image</b><br /><input name="image_upload_box" type="file"
id="image_upload_box" /></p>
<b>Name</b><br /><input type="text" name="aname" />
<br />
<b>Brand</b><br /><input type=text name="abrand" /><br />
<b>Code</b><br /><input type=text name="acode" /><br />
<b>Description</b><br /><textarea rows="12" cols="40" name="adescription"></textarea>
<br />
<b>Product Spec</b><br /><textarea rows="12" cols="40" name="aspec"></textarea><br />
b>Price</b><br /><input type=text name="aprice" /><br />
<input type='submit' id='submit' name='submit' value='Add Product' />
<input type='hidden' value='new' /><br />
<?php include '../inc/edit_products.php'; ?>
</form>
<?php } ?>
This is what i have now, but the form doesnt display now
<?php if (isset($_GET['pid'])) {
$q = mysqli_query($link, "SELECT * FROM products WHERE id = '".$_GET['pid']."'") or
die (mysqli_error());
$row = mysqli_fetch_array($q); ?>
<form class='productsaddform' action='edit_products.php' method='post'
enctype='multipart/form-data' name='image_upload_form' id='image_upload_form'>
<span class='formheading'>Edit Product</span><br /><br />
<p><b>Choose Image</b><br /><input name="image_upload_box" type="file"
id="image_upload_box" /></p>
<b>Name</b><br /><input type="text" name="aname" value=<?php"$row['name'];"?> />
<br />
<b>Brand</b><br /><input type=text name="abrand" /><br />
<b>Code</b><br /><input type=text name="acode" /><br />
<b>Description</b><br /><textarea rows="12" cols="40" name="adescription"></textarea>
<br />
<b>Product Spec</b><br /><textarea rows="12" cols="40" name="aspec"></textarea><br />
<b>Price</b><br /><input type=text name="aprice" /><br />
<input type='submit' id='submit' name='submit' value='Add Product' />
<input type='hidden' value='new' /><br />
<?php include '../inc/edit_products.php'; ?>
</form>
<?php } ?>
EDIT:
Now I want to be able to search products by code in my first form then have that products details displayed in the form in my edit_product page as it is when i edit a product as we sorted. Any idea how to go about this?
This wouldn't be the necessarily the cleanest way to do it, but you could get the information from the db (as you would normally), put it into an array and for each input have something like this:
<input type="text" name="aname" value="<?php echo (isset($array['name'])) ? $array['name'] : ''; ?>" />
Basically, it's an inline if statement that checks to see if the variable is set and if it is, it sets the value of the input to that.
Hope this helps!
If you have any questions on this, let me know :)
EDIT
To answer your question from the comments you could have a link for each product which then takes you to an edit product page e.g.
Link:
AND then just have a page similar to you first page that checks to see if the get variable is set.

Checked checkbox error

What is wrong in this code ? I've tried it on google chrome and the checkbox was UNCKECKED but when trying it on firefox it was checked , how does the code of a CHECKED BOX really have to look like ?
2010-2013 <input type='checkbox' name='actual' value='YES' checked ><br />
2000-2009 <input type='checkbox' name='09' value='YES' > <br />
1990-1999 <input type='checkbox' name='99' value='YES' > <br />
1980-1989 <input type='checkbox' name='89' value='YES' > <br />
1970-1979 <input type='checkbox' name='79' value='YES' > <br />
... -1969 <input type='checkbox' name='69' value='YES' > <br />
<input type='checkbox' name='actual' value='YES' checked="checked" >
Try This.

paypal form not sending data properly

I am trying to submit the following paypal form through a hosted-payment system. however, it does not seem to be passing through any of the variables apart from the price.
Can anyone see where I am going wrong:
<form action='https://securepayments.paypal.com/cgi-bin/acquiringweb' method='post' target='hss_iframe' id='PayPalForm' name='PayPalForm'>
<input type='hidden' name='cmd' value='_hosted-payment' />
<input type='hidden' name='charset' value='utf-8' />
<input type='hidden' name='currency_code' value='GBP' />
<input type='hidden' name='business' value='seller#email.com' />
<input type='hidden' name='paymentaction' value='sale' />
<input type='hidden' name='template' value='TemplateD' />
<input type='hidden' name='return' value='http://yoursite.com/groupon-success.php' />
<input type='hidden' name='notify_url' value='http://yoursite.com/paypal-groupon- ipn.php' />
<input type='hidden' name='item_name' value='Item name' />
<input type='hidden' name='item_number' value='4' />
<input type='hidden' name='subtotal' value='0.01' />
<input type='hidden' name='custom' value='41' />
<input type='hidden' name='address_override' value='true' />
<input type='hidden' name='first_name' value='Jack' />
<input type='hidden' name='last_name' value='Jones' />
<input type='hidden' name='address1' value='address1' />
<input type='hidden' name='city' value='Manchester' />
<input type='hidden' name='zip' value='M20 1AA' />
<input type='hidden' name='country' value='UK' />
<input type='hidden' name='billing_first_name' value='Jack' />
<input type='hidden' name='billing_last_name' value='Jones' />
<input type='hidden' name='billing_address1' value='address1' />
<input type='hidden' name='billing_city' value='Manchester' />
<input type='hidden' name='billing_zip' value='M20 1AA' />
<input type='hidden' name='billing_country' value='UK' />
</form>
it is then been passed to an iframe which seems to work fine using:
<iframe width="100%" scrolling="no" height="580px" frameborder="no" name="hss_iframe" style="float:right;"></iframe>
<script type="text/javascript">
$(function(){
$("#PayPalForm").submit();
});
</script>
Can anyone help with why this data does not seem to pass anything through
--------------- EDIT
Changed cmd to _xclick and passes through fine, so obviously an issue with _hosted-payment
Can anyone give any ideas
If by "however, it does not seem to be passing through any of the variables", you mean it doesn't display the item name / item number: that's correct. Website Payments Pro Hosted Solution doesn't currently support item details. You should remove these parameters as they're not in use for this product.
In addition, the billing/shipping address will be used, but you won't be able to modify them if you're using templateD.

Multiple post data to Mysql DB

I have problem with: I want to create admin for add questions to quiz system. Structure is:
<label>Question 1</label>
<input type='text' name='question' value=''/>
<label>Possible reply</label>
<input type='text' name='1' />
<input type='text' name='2' />
...
<input type='text' name='6' />
<label>**Correct reply</label>
<input type='text' name='correct' />
<label>Question 2 </label>
<input type='text' name='question' value=''/>
<label>Possible reply </label>
<input type='text' name='1' />
<input type='text' name='2' />
...
<input type='text' name='6' />
<label>Correct reply </label>
<input type='text' name='correct' />
<label>Question 3 </label>
...
<input type='submit' name='submit' value='submit'>
And I need multiple questions post to Mysql db tables: question, 1,2,3,4,5,6, correct.
I was create this:
<?php
if(isset($_POST['submit']))
{
$question $_POST['question '];
$a = $_POST['1'];
$b = $_POST['2'];
$c = $_POST['3'];
$d = $_POST['4'];
$e = $_POST['5'];
$f = $_POST['6'];
correct = $_POST['correct '];
$result=mysql_query("insert into test (question, 1, 2, 3, 4, 5, 6, correct) values ('$result', '$a', '$b', '$c', '$d', '$e', '$f', '$correct' )");
}
else
{
?>
<label>Question 1 </label>
<input type='text' name='question' value=''/>
<label>Possible reply </label>
<input type='text' name='1' />
<input type='text' name='2' />
...
<input type='text' name='6' />
<label>Correct reply </label>
<input type='text' name='correct' />
<label>Question 2 </label>
<input type='text' name='question' value=''/>
<label>Possible reply </label>
<input type='text' name='1' />
<input type='text' name='2' />
...
<input type='text' name='6' />
<label>Correct reply </label>
<input type='text' name='correct' />
<label>Question 3 </label>
...
<input type='submit' name='submit' value='submit'>
<?
}
But this send only 1 question to DB.
If you can't use
<input type='text' name='question_1' value=''/>
<input type='text' name='question_1' value=''/>
<input type='text' name='question_1' value=''/>
Write in HTML:
<input type='text' name='question[]' value=''/>
<input type='text' name='reply1[]' />
<input type='text' name='reply2[]' />
<input type='text' name='reply3[]' />
<input type='text' name='reply4[]' />
<input type='text' name='reply5[]' />
<input type='text' name='reply6[]' />
<input type='text' name='correct[]' />
In PHP:
<?php
if (isset($_POST['submit'])){
$questions=$_POST['question'];
$reply1=$_POST['reply1'];
$reply2=$_POST['reply2'];
$reply3=$_POST['reply3'];
$reply4=$_POST['reply4'];
$reply5=$_POST['reply5'];
$reply6=$_POST['reply6'];
$correct=$_POST['correct'];
foreach($questions as $key=>$value){
$result=mysql_query("insert into test (question, 1, 2, 3, 4, 5, 6, correct) values ('$value', '".$reply1[$key]."', '".$reply2[$key]."', '".$reply3[$key]."', '".$reply4[$key]."', '".$reply5[$key]."', '".$reply5[$key]."', '".$correct[$key]."' )");
}
}
It would be nice if you can state your database structure and expected result, because it may not work the way you think and we'll never know until we see it.
If you want 1 answer per row, you need to use a multiple row insertion - How to insert multiple rows in single insert statement?.
try that:
<input type='text' name='question1' value=''/>
<input type='text' name='question2' value=''/>
instead of
<input type='text' name='question1' value=''/>
<input type='text' name='question1' value=''/>

Categories