intermittent sending form using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pxp2002
    New Member
    • Feb 2009
    • 1

    intermittent sending form using PHP

    Hi there -
    My partner and I are new to PHP and were very happy with the enquiry form we created yet it only works sometimes. It was brought to my attention when a prospective client called us after she submitted an enquiry and hadn't heard anything from us. Sometimes it works and sometimes you hit submit then the 'thank you for contacting us page' appears with 'function.mail' underlined and in blue in the top left hand corner - when this occurs we do not receive an email with the information. I cannot find anything that may be causing it. We have tried a number of different PCs, email addresses, operating systems etc... yet there does not seem to be any consistency to why it does or doesn't work. Please find the code below:

    Code:
    <?php
    
    /* Subject and Email Variables */
    
    	$emailSubject = 'PXP Enquiry';
    	$webMaster = 'webmaster@example.com';
    	
    /* Gathering Data Varibles */
    
    	$nameField = $_POST['name'];	
    	$emailField = $_POST['email'];
    	$contactnoField = $_POST['contactno'];
    	$eventdateField = $_POST['eventdate'];
    	$eventtypeField = $_POST['eventtype'];
    	$venueField = $_POST['venue'];
    	$ultraField = $_POST['ultra'];
    	$jamyField = $_POST['jamy'];
    	$motownersField = $_POST['motowners'];
    	$prestigeField = $_POST['prestige'];
    	$fuzzField = $_POST['fuzz'];
    	$qpField = $_POST['qp'];
    	$pxField = $_POST['px'];
    	$ck2Field = $_POST['ck2'];
    	$howdidyoufindusField = $_POST['howdidyoufindus'];
    	$addinfoField = $_POST['addinfo'];
    	$newsletterField = $_POST['newsletter'];
    	
    	$body = <<<EOD
    <br><hr><br>
    Name: $nameField <br>
    Email: $emailField <br>
    Contact No: $contactnoField <br>
    Date of Event: $eventdateField <br>
    Type of Event: $eventtypeField <br>
    Venue Details: $venueField <br>
    Ultra: $ultraField <br>
    Jamy Winehouse: $jamyField <br>
    Motowners: $motownersField <br>
    Prestige: $prestigeField <br>
    Fuzz: $fuzzField <br>
    Quantum: $qpField <br>
    Project X: $pxField <br>
    CK2: $ck2Field <br>
    How Did You Find Us: $howdidyoufindusField <br>
    Additional Info/Requirements: $addinfoField <br>
    Newsletter: $newsletterField <br>
    EOD;
    	
    	$headers = "From: $emailField\r\n";
    	$headers .= "Content-type: text/html\r\n";
    	$success = mail($webMaster, $emailSubject, $body, $headers);
    	
    /* Results rendered as HTML */
    Any ideas/suggestions would be appreciated
    Many Thanks
    Last edited by Markus; Feb 28 '09, 05:33 PM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    I don't see anything wrong with your code (except that the HTML in the message is invalid), so I don't think you have a problem there.

    Could it be that your SMTP server is somewhat unreliable?
    If the SMTP server is down when you try to send a message, PHP would display an error, which includes a link with the function name.

    Did you test the result from the mail function to see if it was successful?
    Like:
    [code=php]
    <?php
    $success = mail(...);
    if($success) {
    echo "Success!";
    } else {
    echo "Sorry, it failed.";
    }
    ?>[/code]


    If none of this is helping, you could try one of the free mail classes.
    The PHPMailer and Swift Mailer classes are both far superior to the PHP mail function.

    And they should provide a lot more helpful info to debug if the problem persists.

    Comment

    Working...