Jump to content

Help! Form, PHP and sendmail issues


Recommended Posts

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!

Link to comment
Share on other sites

Quite right!! the code for the php is:




/* 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 = <<



Name: $nameField


Email: $email_from


First Address Line: $address1Field


Second Address Line: $address2Field


Address Town: $townField


Postcode: $postcodeField


Telephone: $phoneField


Service Enquiry: $serviceField


Send Brochure: $brochureField


How Did They Find Us: $aboutusField


Did They Like Our Site: $oursiteField


Client Comments: $commentsField






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.";





Link to comment
Share on other sites

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 =


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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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 <<


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:




$myString = <<

This is some free form text. It can span mutliple

lines and can contain otherwise troublesome characters like

\ and " and ' without causing any problems.






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!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...