0

Hi,

I have develop a quote form in php and after submission it will e-mail me all the inforamtion correctly but i have problem not getting the information from drop down list and also have browse field so user can upload this file if he wants.

PHP Code:

<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
    $error.="Invalid email address entered";
    $errors=1;
}
if($errors==1) echo $error;
else{
    $values = array ('name','email','company','subject','message');
    $required = array('name','email','company','subject','message');

    $your_email = "kuhashmi@gmail.com";
    $email_subject = "New Message: ".$_POST['subject'];
    $email_content = "new message from contact page:\n";

    foreach($values as $key => $value){
      if(in_array($value,$required)){
        if ($key != 'subject' && $key != 'company') {
          if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
        }
        $email_content .= $value.': '.$_POST[$value]."\n";
      }
    }

    if(@mail($your_email,$email_subject,$email_content)) {

echo "Thanks for your enquiry we will contact you shortly have a nice day. Please check your spam folder also" ;

echo "<script type=\"text/javascript\">";
echo "setTimeout(function(){window.location=\"http://www.moghulweb.com/contact-us.html\"},2000);";
echo "</script>";
}
}
?>

HTML Code

<form action="Quote.php" method="post" class="wpcf7-form" novalidate>                                
                                <p>Your Name (required)<br />
                                    <input id="name" name="name" class="text" /></p>
                                <p>Company Name (required)<br />
                                    <input id="email" name="email" class="text" /> </p>
                                    <p>E-mail Address<br />
                                    <input id="company" name="company" class="text" /> </p>
                                <p>Budget<br />
                                    <input id="subject" name="subject" class="text" /> </p>
                                    <p>Nature of Business<br />
                                    <input id="subject" name="subject" class="text" /> </p>
                                    <p>Type of Website
                                        <select name="type">
                                            <option>PSD to HTML</option>
                                            <option>PSD to WP</option>
                                            <option>PSD to PHP</option>
                                        </select></p>
                                    <p>Number of Pages<br />
                                    <input id="subject" name="subject" class="text" /> </p>
                                    <p>Upload File -(jpg, PDF, DOC, gif)
                                    <label for="file"></label>
<input type="file" name="file" id="file" /></p> 
                                <p>Company Description<br />
                                    <textarea id="message" name="message"  cols="40" rows="10"></textarea> </p>
                                <p><input type="submit" value="SUBMIT" /></p>
                                <div ></div></form>

can't get value from Select and Browse field.

Thanks

2
Contributors
1
Reply
17
Views
3 Years
Discussion Span
Last Post by cereal
0

First problem:

<p>Budget<br />
<input id="subject" name="subject" class="text" /> </p>
<p>Nature of Business<br />
<input id="subject" name="subject" class="text" /> </p>

Here you have two input fields with same id and the same name, you can use the same name, as long you use an array name=subject[] but it's better to set different names. Regarding the id, instead, it should be unique over the page.

To get the values from the select tag, just use $_POST['type'], but it's better to set the attribute value to the option tag:

<select name="type">
    <option value="1">PSD or HTML</option>
    <option value="2">PSD to WP</option>
    <option value="3">PSD to PHP</option>
</select>

To access the uploaded file you need to access the $_FILES array. For more information check:

Anyway, sending attachments with mail() is painful for you and resource intensive for the server, you should consider using a library like Swift Mailer:

Or, better, save the uploaded file to the server and send only the link to it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.