SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Dec 2001
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Issues in PHP

    I have an issue where a form is not submitting and it seems that the PHP version might have been updated which could be causing this. The current version of PHP is 5.1.6 and all of the sudden the form stopped working. Could someone please review and let me know what could be causing this?

    This is the page that holds the actual form being filled out:

    PHP Code:
    <form action="contact-success.php" method="post" onSubmit="MM_validateForm('First_Name','','R','Last_Name','','R','Email','','RisEmail');return document.MM_returnValue">
                              <
    table cellpadding="0" cellspacing="0" border="0">
                                <
    tr>
                                  <
    td>Are you interested in:</td>
                                  <
    td style="padding-left:10px">
                                    <
    input type="checkbox" name="Interests[]" value="Solo Direct Mail">Solo Direct Mail (USA Only)<br>
                                    <
    input type="checkbox" name="Interests[]" value="Mailing Lists">Mailing Lists<br>
                                    <
    input type="checkbox" name="Interests[]" value="Print Brokerage">Print Brokerage<br>
                                    <
    input type="checkbox" name="Interests[]" value="Pay Per Click Campaigns">Pay Per Click Campaigns<br>
                                    <
    input type="checkbox" name="Interests[]" value="Search Engine Optimization">Search Engine Optimization<br>
                                    <
    input type="checkbox" name="Interests[]" value="Search Engine Marketing">Search Engine Marketing<br>
                                    <
    input type="checkbox" name="Interests[]" value="Website Design">Website Design<br>
                                  </
    td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>* First Name:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="First_Name" id="First_Name"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>* Last Name:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="Last_Name" id="Last_Name"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>* E-mail:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="Email" id="Email"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>Title:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="Title" id="Title"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>Company Name:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="Company_Name" id="Company_Name"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>Street Address:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="Street_Address"id="Street_Address"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>City:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="City" id="City"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>State:</td>
                                  <
    td style="padding-left:10px">
                                    <
    select name="State" id="State">
                                      <
    option value="Alabama">Alabama</option>
                                      <
    option value="Alaska">Alaska</option>
                                      <
    option value="Arizona">Arizona</option>
                                      <
    option value="Arkansas">Arkansas</option>
                                      <
    option value="California">California</option>
                                      <
    option value="Colorado">Colorado</option>
                                      <
    option value="Connecticut">Connecticut</option>
                                      <
    option value="Delaware">Delaware</option>
                                      <
    option value="District of Columbia">District of Columbia</option>
                                      <
    option value="Florida">Florida</option>
                                      <
    option value="Georgia">Georgia</option>
                                      <
    option value="Hawaii">Hawaii</option>
                                      <
    option value="Idaho">Idaho</option>
                                      <
    option value="Illinois">Illinois</option>
                                      <
    option value="Indiana">Indiana</option>
                                      <
    option value="Iowa">Iowa</option>
                                      <
    option value="Kansas">Kansas</option>
                                      <
    option value="Kentucky">Kentucky</option>
                                      <
    option value="Louisiana">Louisiana</option>
                                      <
    option value="Maine">Maine</option>
                                      <
    option value="Maryland">Maryland</option>
                                      <
    option value="Massachusetts">Massachusetts</option>
                                      <
    option value="Michigan">Michigan</option>
                                      <
    option value="Minnesota">Minnesota</option>
                                      <
    option value="Mississippi">Mississippi</option>
                                      <
    option value="Missouri">Missouri</option>
                                      <
    option value="Montana">Montana</option>
                                      <
    option value="Nebraska">Nebraska</option>
                                      <
    option value="Nevada">Nevada</option>
                                      <
    option value="New Hampshire">New Hampshire</option>
                                      <
    option value="New Jersey">New Jersey</option>
                                      <
    option value="New Mexico">New Mexico</option>
                                      <
    option value="New York">New York</option>
                                      <
    option value="North Carolina">North Carolina</option>
                                      <
    option value="North Dakota">North Dakota</option>
                                      <
    option value="Ohio">Ohio</option>
                                      <
    option value="Oklahoma">Oklahoma</option>
                                      <
    option value="Oregon">Oregon</option>
                                      <
    option value="Pennsylvania">Pennsylvania</option>
                                      <
    option value="Rhode Island">Rhode Island</option>
                                      <
    option value="South Carolina">South Carolina</option>
                                      <
    option value="South Dakota">South Dakota</option>
                                      <
    option value="Tennessee">Tennessee</option>
                                      <
    option value="Texas">Texas</option>
                                      <
    option value="Utah">Utah</option>
                                      <
    option value="Vermont">Vermont</option>
                                      <
    option value="Virginia">Virginia</option>
                                      <
    option value="Washington">Washington</option>
                                      <
    option value="West Virginia">West Virginia</option>
                                      <
    option value="Wisconsin">Wisconsin</option>
                                      <
    option value="Wyoming">Wyoming</option>
                                    </
    select>
                                  </
    td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>Zip:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="Zip" id="Zip"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>Country:</td>
                                  <
    td style="padding-left:10px">
                                    <
    select name="Country" id="Country">
                                      <
    option value="USA">USA</option>
                                      <
    option value="Outside of the USA">Outside of the USA</option>
                                    </
    select>
                                  </
    td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>Phone:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="Phone" id="Phone"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>Fax:</td>
                                  <
    td style="padding-left:10px"><input type="text" name="Fax" id="Fax"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td colspan="2">Have you ever used direct mail to market your business?</td>
                                </
    tr>
                                <
    tr>
                                  <
    td>&nbsp;</td>
                                  <
    td style="padding-left:10px">
                                    <
    input type="radio" name="Direct_Mail" value="Yes" />Yes &nbsp;
                                    <
    input type="radio" name="Direct_Mail" value="No" />No</td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td>If so how often?</td>
                                  <
    td style="padding-left:10px"><input type="text" name="Direct_Mail_Often" id="Direct_Mail_Often"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td colspan="2">Question or Comment</td>
                                </
    tr>
                                <
    tr>
                                  <
    td colspan="2"><textarea name="Comments" id="Comments" cols="50" rows="5"></textarea></td>
                                </
    tr>
                                <
    tr>
                                  <
    td height="10" colspan="2"><img height="10" width="1" src="images/spacer.gif"></td>
                                </
    tr>
                                <
    tr>
                                  <
    td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
                                </
    tr>
                              </
    table>
                            </
    form
    On the next page here is the code that processes the email:

    PHP Code:
    <?
    foreach ($_POST['Interests'] as $intFull) {
     
    $Interests .= "$intFull\r\n";
    }
    $First_Name $_POST['First_Name'];
    $Last_Name $_POST['Last_Name'];
    $Email $_POST['Email'];
    $Title $_POST['Title'];
    $Company_Name $_POST['Company_Name'];
    $Street_Address $_POST['Street_Address'];
    $City $_POST['City'];
    $State $_POST['State'];
    $Zip $_POST['Zip'];
    $Country $_POST['Country'];
    $Phone $_POST['Phone'];
    $Fax $_POST['Fax'];
    $Direct_Mail $_POST['Direct_Mail'];
    $Direct_Mail_Often $_POST['Direct_Mail_Often'];
    $Comments $_POST['Comments'];
    $to  'test1@email.com' ', ';
    $to .= 'test2@email.com';
    $subject "Contact Request";
    $body "Interested in:
    $Interests
    First Name: 
    $First_Name
    Last Name: 
    $Last_Name
    E-mail: 
    $Email
    Title: 
    $Title
    Company Name: 
    $Company_Name
    Street Address: 
    $Street_Address
    City: 
    $City
    State: 
    $State
    Zip: 
    $Zip
    Country: 
    $Country
    Phone: 
    $Phone
    Fax: 
    $Fax
    Used Direct Mail: 
    $Direct_Mail
    How Often: 
    $Direct_Mail_Often
    Comments: 
    $Comments";
    $headers 'From:' .$Email"\r\n" .
     
    'BCC: test3@email.com' "\r\n" .
     
    'Reply-To:' .$Email"\r\n" .
     
    'X-Mailer: PHP/' phpversion();
    mail($to$subject$body$headers);
    ?>
    Obviously the email addresses have been changed. If anyone could help that would be very appreciated!

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To debug, try print_r() every variable you're using to send email ($to, $subject, $body, $headers).

    Also, try replacing

    PHP Code:
    mail($to$subject$body$headers); 
    with

    PHP Code:
    if (mail($to$subject$body$headers))
    {
        echo 
    "Email sent";
    }
    else
    {
        echo 
    "Error sending email";


  3. #3
    SitePoint Addict
    Join Date
    Dec 2001
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did exactly that and the page displayed Email Sent and all of the variables showed up. We have tried changing the email address to about 10 different ones to make sure it was not getting blocked. Is there anything wrong with the code that would keep it from working?

  4. #4
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding \r\n after phpversion(). I don't think all caps for Bcc would be an issue, but just in case.

    PHP Code:
    $headers 'From:' .$Email"\r\n" .
     
    'Bcc: test3@email.com' "\r\n" .
     
    'Reply-To:' .$Email"\r\n" .
     
    'X-Mailer: PHP/' phpversion()."\r\n"

  5. #5
    SitePoint Addict
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This may not be the issue but make sure the opening PHP tag is <?php, not <?

    Also, it looks like you've got a JavaScript function evaluating the form fields before allowing the post to go through. You might want to try getting rid of the onsubmit function to test the script first and narrow down whether or not the JS script is interfering.

    Also, it might be best to validate the form fields in PHP as well in order to avoid email form injections ... a script posting directly to your form will not be evaluated by JS.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •