Topic: Help! Form, PHP and sendmail issues

Hi, I am  am trying to set up a web site and on the site I have a couple of forms I created in DW, and a PHP script to send the data via email. Easy enough!

However I have an issue, the PHP script will only divert to the success url if the user enters data into all the form elements. However, there are no required fields in the form, the script does send the email irrespective of data input into the form, it just doesn't divert to the success URL.


Can anyone please give me some advice on this????

Thanks in advance!

Re: Help! Form, PHP and sendmail issues

You will need to provide a link to your page or at least provide the code that you are having an issue with.

Re: Help! Form, PHP and sendmail issues

A link won't work. The code is needed since there is php involved.

Re: Help! Form, PHP and sendmail issues

Quite right, sorry for my slip up, I should have remembered that PHP doesn't show up in source code before I posted, I get those tongue moments sometimes..!

Re: Help! Form, PHP and sendmail issues

Quite right!!  the code for the php is:

<?php

/* Subject and Email Variables */

    $email_to = "enquiries@kyu-images.com";
    $email_subject = "General Enquiry";
    $thankyou_url = "http://www.kyu-images.com/contact-us/email_sent.html";

   
/* Gathering Data Variables */

    $nameField = $_POST["name"];
    $email_from = $_POST["email"];
    $address1Field = $_POST["address1"];
    $address2Field = $_POST["address2"];
    $townField = $_POST["town"];
    $postcodeField = $_POST["postcode"];
    $phoneField = $_POST["phone"];
    $serviceField = $_POST["service"];
    $brochureField = $_POST["brochure"];
    $aboutusField = $_POST["aboutus"];
    $oursiteField = $_POST["oursite"];
    $commentsField = $_POST["comments"];
   
    $headers  = "From: $email_from . \r\n";
    $headers .= "Reply-To: $email_from . \r\n";
    $headers .= "Content-type: text/html\r\n";
   
    $message = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $email_from <br>
First Address Line: $address1Field <br>
Second Address Line: $address2Field <br>
Address Town: $townField <br>
Postcode: $postcodeField <br>
Telephone: $phoneField <br>
Service Enquiry: $serviceField <br>
Send Brochure: $brochureField <br>
How Did They Find Us: $aboutusField <br>
Did They Like Our Site: $oursiteField <br>
Client Comments: $commentsField <br>
<br><hr><br>
EOD;
   
    ini_set("sendmail_from", $email_from);
    $sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from);

   
/*Results Rendered As HTML */

if($sent) {
        header("Location: " . $thankyou_url);     // Redirect customer to thankyou page
    } else {
        // The mail didn't send, display an error.
        echo "There has been an error sending your message. Please try later.";
    }


?>

Re: Help! Form, PHP and sendmail issues

In your post of the PHP code you have:-

$sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from);
   
/*Results Rendered As HTML */

if($sent) {
        header("Location: " . $thankyou_url);  

Is /*Results Rendered As HTML */ something you only put in the post or is it in the PHP code? If so it should be //Results Rendered As HTML :-

$sent = mail($email_to, $email_subject, $message, $headers, "-f" . $email_from);
   
//Results Rendered As HTML 

if($sent) {
        header("Location: " . $thankyou_url);  

because the way it is now the code will send the email and stop before it gets to the if($sent)

I don't fully understand the

$message = <<<EOD..............EOD;

Shouldn't that be in " like $message = "EOD..............EOD";

Re: Help! Form, PHP and sendmail issues

The Comment block should be fine there.

/* 
 *    This is the main page comment block.
 *    This page includes the configuration file, 
 *    the templates, and any content-specific modules.
 */

Single line comments are the double slash.

Echo the value of $sent right after the mail function to see what it contains. Do you have errors set to display?

Re: Help! Form, PHP and sendmail issues

I dont think the comments format ahould make much difference, its just weird that the page only redirects if all the fields are filled in on the form. it sends the email either way, its just the redirection that seems to be a problem.  sveral people have looked at it for me and seem to think the code is sound, and that it must be a host issue, preventing it somehow, though i'm not entirely sure why or how!

Re: Help! Form, PHP and sendmail issues

Incidently the EOD is a way that allows free text within PHP
The PHP heredoc string syntax allows free form text to be used without having to worry about escaping special characters such as quotes and backslashes. The content of the heredoc string is wrapped with <<<EOD and EOD; markers.

The only rules are that the closing EOD; must be at the beginning of the last line, and the only content on that line, as follows:

<?php

$myString = <<<EOD
This is some free form text. It can span mutliple
lines and can contain otherwise troublesome characters like
\ and " and ' without causing any problems.
EOD;

?>


So this shouldn't be the issue either, and my host have emailed me to say that as the email actually sends, it isn't an issue with them, however a script issue that is causing an error witin the server!!!

I feel i have experience in banging my head against a concrete wall!!