0

I've used this same script before and it works on another form on the same server, but for some reason this time it isn't working and I can't figure out why.

HTML Form:

<form method="post" action="#" class="dealer-form" enctype="multipart/form-data">
<input type="hidden" name="form-type" value="dealer">

    <p><label for="companyname"><span class="required">*</span> Company Name:</label> <input type="text" id="companyname" name="companyname" value="" class="form-control" required /></p>
    <p><label for="name"><span class="required">*</span> Your Name:</label> <input type="text" id="name" name="name" value="" class="form-control" required /></p>
    <p><label for="email"><span class="required">*</span> Email Address:</label> <input type="email"id="email" name="email" value="" class="form-control" required /></p>
    <p><label for="phone"><span class="required">*</span> Phone Number:</label> <input type="tel" id="phone" name="phone" value="" class="form-control" required /></p>
    <p><label for="position"><span class="required">*</span> Your Company Position:</label> <input type="text" id="position" name="position" value="" class="form-control" required /></p>
    <p><label for="street"><span class="required">*</span> Street Address:</label> <input type="text" id="street" name="street" value="" class="form-control" required /></p>
    <p><label for="city"><span class="required">*</span> City:</label> <input type="text" id="city" name="city" value="" class="form-control" required /></p>
    <p><label for="state"><span class="required">*</span> State:</label> <input type="text" id="state" name="state" value="" class="form-control" required /></p>
    <p><label for="zip"><span class="required">*</span> Zip:</label> <input type="text" id="zip" name="zip" value="" class="form-control" required /></p>

    <hr class="new" />

    <p><label for="fedtax">Federal Tax ID#:</label> <input type="text" id="fedtax" name="fedtax" value="" class="form-control" /></p>
    <p><label for="salestax">Sales Tax Permit # (If applicable for your state):</label> <input type="text" id="salestax" name="salestax" value="" class="form-control" /></p>
    <p><label for="license">Security Installer License # (If applicable for your state):</label> <input type="text" id="license" name="license" value="" class="form-control" /></p>

    <h4><span class="required">*</span> Is installing or reselling CCTV or Security Equipment your full time occupation?</h4>
    <p>
    <input name="occupation" value="Yes" type="radio" required />
    <span  class="lbl padding-8">Yes</span>
    </p>

    <p>
    <input name="occupation" value="No" type="radio" required />
    <span  class="lbl padding-8">No</span>
    </p>


    <h4><span class="required">*</span> How long have you been in the business of reselling or installing CCTV?</h4>
    <p>
    <input name="exp" value="Less than 1 year" type="radio" required />
    <span  class="lbl padding-8">Less than 1 Year</span>
    </p>

    <p>
    <input name="exp" value="1 to 5 Years" type="radio" required />
    <span  class="lbl padding-8">1 to 5 Years</span>
    </p>

    <p>
    <input name="exp" value="Over 5 Years" type="radio" required />
    <span  class="lbl padding-8">Over 5 Years</span>
    </p>

    <h4>Security License Certificates, Sales Tax Permits & Resellers Permit:</h4>
    <p><input type="file" id="upload" name="upload[]" multiple></p>

<input type="submit" name="submit" value="Submit Application">
</form>

And here is the php that I've included on the same page as the form:

if( isset($_POST['form-type']) ){

if( $_POST['form-type'] == 'dealer' ){

$to = 'myemail@mydomain.com';

$headers = "From: applications@mydomain.com" . "\r\n";
$headers .= "Reply-To:" . strip_tags($_POST['email']) . "\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


   $companyname = trim(strip_tags($_POST['companyname']));
   $name = trim(strip_tags($_POST['name']));
   $email = trim(strip_tags($_POST['email']));
   $phone = trim(strip_tags($_POST['phone']));
   $position = trim(strip_tags($_POST['position']));
   $street = trim(strip_tags($_POST['street']));
   $city = trim(strip_tags($_POST['city']));
   $state = trim(strip_tags($_POST['state']));
   $zip = trim(strip_tags($_POST['zip']));
   $fedtax = trim(strip_tags($_POST['fedtax']));
   $salestax = trim(strip_tags($_POST['salestax']));
   $license = trim(strip_tags($_POST['license']));
   $occupation = trim(strip_tags($_POST['occupation']));
   $exp = trim(strip_tags($_POST['exp']));

    $body = "<html><body>";
    $body .= "<h3>Contact Information:</h3>";
    $body .= "<p><strong>Name:</strong> $name </p>";
    $body .= "<p><strong>Email:</strong> $email </p>";
    $body .= "<p><strong>Phone Number:</strong> $phone </p>";
    $body .= "<h3>Address:</h3>";
    $body .= "<p> $address <br/>";
    $body .= "$city, $state $zip </p>";

    $body .= "<h3>Company Information:</h3>";
    $body .= "<p><strong>Company Name:</strong> $companyname </p>";
    $body .= "<p><strong>Company Position:</strong> $position </p>";
    $body .= "<p><strong>Federal Tax ID#:</strong> $fedtax </p>";
    $body .= "<p><strong>Sales Tax Permit # (If Applicable):</strong> $sales </p>";
    $body .= "<p><strong>Security Installer License # (If Applicable):</strong> $license </p>";
    $body .= "<p><strong>Is installing or reselling CCTV or Security Equipment your full time occupation?</strong> $occupation </p>";
    $body .= "<p>I have <strong>$exp</strong> experience in the business of reselling or installing CCTV</p>";
    $body .= "</body></html>";

   $subject = "New Dealer Application";

}



mail($to, $subject, $body, $headers);
header('Location:  ' . $this->getUrl('dealers/success'));
exit();

}
AJK
  • 391
  • 9
  • 27
  • Have you properly configured your server so it can send mails ? – D4V1D Mar 30 '15 at 17:09
  • Yes, I just tested another form we have on the site that uses the same script (just different inputs and such) and it works just fine, not sure what's wrong with this one. – AJK Mar 30 '15 at 17:11
  • Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Mar 30 '15 at 17:14
  • @Fred-ii- , I just edited my code in the OP, added `.=` to the 2nd `$body` , tested it out and still no luck – AJK Mar 30 '15 at 17:16
  • Well, I see `` and this tells me you want to attach or upload a file. Your form requires a valid enctype to be added. – Funk Forty Niner Mar 30 '15 at 17:18
  • @Fred-ii- added error reporting and nothing comes up. As for the `` I haven't declared that into my php file yet, I was going to tackle that after I got the rest of the form working. I just tested taking it out of the HTML though and stills same result – AJK Mar 30 '15 at 17:23
  • I tested your code with no issues. I created 2 files; one for the form and another for the PHP, replacing `action="#"` with `action="handler.php"` - So, if you've some JS/Ajax you're not showing us and is used in conjunction with this, please show it. Other than that, am unable to replicate the problem. Plus seeing `$this->getUrl` this tells me you're using a class. – Funk Forty Niner Mar 30 '15 at 17:27
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/74125/discussion-between-aj47-and-fred-ii). – AJK Mar 30 '15 at 17:30

0 Answers0