Php Form - Code error I can't figure out

Hi There,

I wrote some PHP code for a simple “Contact Us” page for a website I’m working on, but it doesn’t seem to be working. I do get the emails, though the email addy is that of the hosting co. and not the user whom filled out the form, the Subject line I specified doesn’t come over, neither does any of the other fields in form either. I’ve copied and pasted the code below, PLEASE let me know if anyone out there can offer some assistance. Also, the website that this is for is www.weddingsandmore.us

Thanks a TON in advance - this one has me stumped. ::slight_smile: THANKS!

<?php // Subject and email Variables $EmailSubject = 'Weddings and More Inquiry'; $webMaster = '[email protected]'; //Gathering Data Variables $nameField = $_POST['name']; $emailField = $_POST['email']; $weddingdateField = $_POST['weddingdate']; $guestsField = $_POST['guests']; $messageField = $_POST['message']; // Prepare email body text $body = <<<EOD


Name: $name
Email: $email
Wedding Date: $weddingdate
No of Guests: $guests
Message: $message
EOD; // Sending Email $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail ($webMaster, $$EmailSubject, $body, $headers); // Results rendered as html $theResults = <<<EOD Weddings and More
Homepage   Why   About us   Weddings     Contact Us

Thank you...

Thank you for contacting Weddings and More!

We will be in touch...

 


Footer
EOD; echo "$theResults"; ?>

Hope to hear from someone soon… ;D

-Dre

Wrong variable names in the body and double ‘$’ signs before EmailSubject, try this:

[php]

// Subject and email Variables

$EmailSubject = ‘Weddings and More Inquiry’;
$webMaster = ‘[email protected]’;

//Gathering Data Variables

$nameField = $_POST[‘name’];
$emailField = $_POST[‘email’];
$weddingdateField = $_POST[‘weddingdate’];
$guestsField = $_POST[‘guests’];
$messageField = $_POST[‘message’];

// Prepare email body text

$body = <<<EOD




Name: $nameField

Email: $emailField

Wedding Date: $weddingdateField

No of Guests: $guestsField

Message: $messageField

EOD;

// Sending Email

$headers = “From: $emailField\r\n”;
$headers .= “Content-type: text/html\r\n”;
$success = mail ($webMaster, $EmailSubject, $body, $headers);[/php]

Thank you!!! You are a lifesaver! ;D

One more thing…

I get the email with all the results all correctly and then I get another email from my host provider with the form fields but no results. I see in the email results code portion it has a $webmaster variable and I tried removing it and then I received no emails. Is this something that is a setting through my web hoster or is this something I can change/add in the code?

Thanks again…
-Andrea

if the email is always being sent to the same email address with the same subject you can change it to:

[php]
$success = mail (’…your email address…’, ‘Weddings and More Inquiry’, $body, $headers);
[/php]

obviously change the ‘…your email address…’ to the address you want the messages sent to. Should then send directly to you only once.

I guess that was an ignorant question - sorry. I changed it to my email and it still sends one from the host - I should have been clear about that. I played around with a bunch of the email results code and nothing prevented a 2nd email from the host from being sent along with the one from the user.

Sorry, my fault, I just didn’t read the problem right. I can’t see anything wrong in the code, however I have only ever used mail() once and am therefore not hugely knowledgeable about it.

You could try simplifying it and not declare the headers, and just have the email sent in plain text. Do you need it in HTML formatting? If not try:
[php]

<?php // Subject and email Variables $EmailSubject = 'Weddings and More Inquiry'; $webMaster = '[email protected]'; //Gathering Data Variables $nameField = $_POST['name']; $emailField = $_POST['email']; $weddingdateField = $_POST['weddingdate']; $guestsField = $_POST['guests']; $messageField = $_POST['message']; // Prepare email body text $body = "Sender: $nameField \n\n Email: $emailField \n\n Wedding Date: $weddingdateField\n\n Guests: $guestField \n\n Message: $messageField\n\n"; // Sending Email $success = mail ($webMaster, $EmailSubject, $body); ?>

[/php]
If that doesn’t work im stumped.

That didn’t work - ugh.

If I remove the echo “$theResults”; from the bottom it will only send me one email from the user, BUT it doesn’t load the “thank you” page after, it’s just a white page (as it is send.php in the URL)

Thanks for all your help on this! I’ll survive with it how it is right now for the time being and see if I can find someone down the road that knows what to tweak…

-Dre

you could try taking out the " mail ($webMaster, $$EmailSubject, $body, $headers) " from where it is now and put it at the end where the “echo $theResults” is…

[php]

<?php // Sending Email //mail() gone $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; // Results rendered as html $theResults = <<

[/php]

Give that a go, might fix it… we hope.

Nope, that causes a syntax error to pop up instead of the thank or error page and no emails are sent :frowning:

This is turning out to be a harder fix then I ever thought.

Thanks for the help!

-Dre

Sponsor our Newsletter | Privacy Policy | Terms of Service