0

I am new to PHP and I have a contact form on my website where the last field is a dropdown menu from which you need to select an option. The form gets returned with all the info except the option selected in the dropdown menu.

My coding: HTML

 <select id="Product Enquiry" name="productenquiry">
  <option value="Brochure Design">Brochure Design</option>
  <option value="Corporate Packages">Corporate Packages</option>
  <option value="Flyer Design">Flyer Design</option>
  <option value="Logo Design">Logo Design</option>
  <option value="Web Design">Web Design</option>
  <option value="Other">Other</option>
 </select>

PHP

<?php

$name = $_GET['name'] ; 
$cellnumber = $_GET['cellnumber'] ; 
$email = $_GET['email'] ; 
$comments = $_GET['comment'] ;
    $product = $_GET['productenquiry'] ;

if (($name=="")||($email=="")) {
    print("<Script>alert('Please complete the name and e-mail details.');window.history.back();</script>") ;
} else {

$content = "<b>Name:</b> " . $name ."   <br><br> <b>Cell Number:</b> " . $cellnumber ."   <br><br><b>E-mail:</b> " . $email . " <br><br> <b>Comments:</b> " . $comments . " <br>    <br> <b>Product:</b> " . $productenquiry . " <br>";
$admin = "info@ceedeecee.co.za" ;

$from = "info@ceedeecee.co.za"; 
$subject = "Please Quote Me!"; 

$html_data = "<HTML><BODY><table width=100% bgcolor=#dddddd cellspacing=1 cellpadding=10 align=center>
        <tr bgcolor=white><td><font size=2 face=verdana><Br><br>".$content."</font></tr></table></BODY></HTML>"; 

$headers = "Content-Type: text/html; charset=iso-8859-1\r\n" ; 
$headers .= "From: info@ceedeecee.co.za\r\n";
$mail = mail($admin, $subject, $html_data, $headers);


if (!$mail) {

    print("<Script>alert('Unfortunately there has been an error. Please try again in 5 minutes.');window.history.back();</script>") ;


} else {


    print("<Script>alert('Thank-you for your email! We will be in touch with you soon!');window.location='http://www.ceedeecee.co.za/';</script>") ;



}
}
?>

Any help would be greatly appreciated!

UPDATE: THIS WORKS!

PHP

$name = $_GET['name'] ; 
$cellnumber = $_GET['cellnumber'] ; 
$email = $_GET['email'] ; 
$comments = $_GET['comment'] ;
$productenquiry = $_GET['productenquiry'] ;
digitalia_shy
  • 13
  • 1
  • 5

5 Answers5

1

This might be the case..

you have assigned

$product = $_GET['productenquiry'];

and used $productenquiry in

$content = " .....<br> <b>Product:</b> " . $productenquiry //$product . " <br>";
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Khem
  • 184
  • 7
1

If your form method is get then you can get this value using:

$Your_variable = $_GET['productenquiry'] ;

and if your form method is post then you can get this value using:

$Your_variable = $_POST['productenquiry'] ;
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Ashoka Mondal
  • 1,161
  • 4
  • 12
  • 28
0

Try this... with $_REQUEST and make sure your form close before this productenquiry dropdown.

$name = $_REQUEST['name'] ;
$cellnumber = $_REQUEST['cellnumber'] ;
$email = $_REQUEST['email'] ;
$comments = $_REQUEST['comment'] ;
$product = $_REQUEST['productenquiry'] ;

if (($name=="")||($email=="")) {
    print("<Script>alert('Please complete the name and e-mail details.');window.history.back();</script>") ;
} else {

$content = "<b>Name:</b> " . $name ."   <br><br> <b>Cell Number:</b> " . $cellnumber ."   <br><br><b>E-mail:</b> " . $email . " <br><br> <b>Comments:</b> " . $comments . " <br>    <br> <b>Product:</b> " . $productenquiry . " <br>";
$admin = "info@ceedeecee.co.za" ;

$from = "info@ceedeecee.co.za";
$subject = "Please Quote Me!";

$html_data = "<HTML><BODY><table width=100% bgcolor=#dddddd cellspacing=1 cellpadding=10 align=center>
        <tr bgcolor=white><td><font size=2 face=verdana><Br><br>".$content."</font></tr></table></BODY></HTML>";

$headers = "Content-Type: text/html; charset=iso-8859-1\r\n" ;
$headers .= "From: info@ceedeecee.co.za\r\n";
$mail = mail($admin, $subject, $html_data, $headers);


if (!$mail) {

    print("<Script>alert('Unfortunately there has been an error. Please try again in 5 minutes.');window.history.back();</script>") ;


} else {


    print("<Script>alert('Thank-you for your email! We will be in touch with you soon!');window.location='http://www.ceedeecee.co.za/';</script>") ;



}
}
?>
Zeeshan
  • 1,659
  • 13
  • 17
0

At first, make sure that select tag is in form tag. Then, if it's still not work, paste your full html.

Note: You should use POST method like this

<form action="/your/post/url" method="post">

and get request value

$_POST['param_key']
Ryo Mikami
  • 309
  • 1
  • 5
0

Use the below html and php code There are white spaces problem in your code.

HTML

<select id="productenquiry" name="productenquiry">
  <option value="Brochure Design">Brochure Design</option>
  <option value="Corporate Packages">Corporate Packages</option>
  <option value="Flyer Design">Flyer Design</option>
  <option value="Logo Design">Logo Design</option>
  <option value="Web Design">Web Design</option>
  <option value="Other">Other</option>
</select>

PHP

<?php

$name = $_GET['name'] ; 
$cellnumber = $_GET['cellnumber'] ; 
$email = $_GET['email'] ; 
$comments = $_GET['comment'] ;
$product = $_GET['productenquiry'] ;

if (($name=="")||($email=="")) {
    print("<Script>alert('Please complete the name and e-mail details.');window.history.back();</script>") ;
} else {

$content = "<b>Name:</b> " . $name ."   <br><br> <b>Cell Number:</b> " . $cellnumber ."   <br><br><b>E-mail:</b> " . $email . " <br><br> <b>Comments:</b> " . $comments . " <br>    <br> <b>Product:</b> " . $productenquiry . " <br>";
$admin = "info@ceedeecee.co.za" ;

$from = "info@ceedeecee.co.za"; 
$subject = "Please Quote Me!"; 

$html_data = "<HTML><BODY><table width=100% bgcolor=#dddddd cellspacing=1 cellpadding=10 align=center>
        <tr bgcolor=white><td><font size=2 face=verdana><Br><br>".$content."</font></tr></table></BODY></HTML>"; 

$headers = "Content-Type: text/html; charset=iso-8859-1\r\n" ; 
$headers .= "From: info@ceedeecee.co.za\r\n";
$mail = mail($admin, $subject, $html_data, $headers);


if (!$mail) {

    print("<Script>alert('Unfortunately there has been an error. Please try again in 5 minutes.');window.history.back();</script>") ;


} else {


    print("<Script>alert('Thank-you for your email! We will be in touch with you soon!');window.location='http://www.ceedeecee.co.za/';</script>") ;



}
}
?>
user2486495
  • 1,709
  • 11
  • 19