PDA

View Full Version : Submiting form to email addy via PHP


Wynnefield
03-21-2005, 08:59 PM
i was reading a php resource book at B&N last week or two, and it had some great examples of submitting a form to a .php page to route to an email address and display an echo message to the web visitor ...

any examples would be much appreciated ... thank you

Chroder
03-21-2005, 10:07 PM
http://www.snipe.net/content/view/19/42/

There's a good one that shows how to send a multipart (HTML and plaintext versions) email.

Wynnefield
03-22-2005, 11:30 PM
thank you chroder ... i will check it out

Wynnefield
03-24-2005, 12:50 AM
not much help from the site ... i found a book today with the perfect code snippets; however, after submitting the button on the contact.html page with <form action="contact.php" method="post"...>, i receive:

"parse error, unexpected T_STRING, expecting ']' .../contact.php on line 63"

the line referred to in the error is the $formsent = mail (...) line in the following code in contact.php:

<?php
/* receive and email form data from contact.html */
$name = $_POST['contact_name'];
$company = $_POST['contact_company'];
$email = $_POST['contact_email'];
$phone = $_POST['contact_phone'];
$subject = $_POST['contact_topic'];
$comments = $_POST['contact_comments];
$formsent = mail('wynne@wynnefields.com', $subject, $comments);
if ($formsent)
{echo "Thank you, $name. We have received your comments, and will respond with the next 48 hours.";}
else
(echo "We are currently experiencing problems with our contact form and apologize for any inconvenience. Please try again at your convenience.";)
?>

PLEASE HELP!! ... thank you (the winkie face is actually a ";" and ")" in the php code)

Chroder
03-24-2005, 01:34 AM
Use bbcode (http://www.webdesignforum.com/misc.php?do=bbcode) to post code.

Anyway,
else
(echo "We are currently experiencing problems with our contact form and apologize for any inconvenience. Please try again at your convenience.");

Is incorrect, replace with:

else
{
echo "We are currently experiencing problems with our contact form and apologize for any inconvenience. Please try again at your convenience.";
}

Wynnefield
03-24-2005, 09:33 AM
thank you for the posting hint ... do you have any idea how to resolve my error??

Chroder
03-24-2005, 05:17 PM
Ah yes,

$comments = $_POST['contact_comments];

You are missing a quote.

$comments = $_POST['contact_comments'];

Wynnefield
03-24-2005, 10:57 PM
oh my gosh! have you every looked at a piece of code for so long, you just can't see it right in front of your face???? ... thank you chroder

i owe ya one! ...

Chroder
03-24-2005, 11:53 PM
If you post it into the [php ] bbcodes, you can easily tell the missing quote ;)

Try getting an editor with syntax highlighting, too. Like PHP Designer (http://www.mpsoftware.dk/phpdesigner.php) (free) or EditPlus (http://www.editplus.com/) (free eval).

Wynnefield
03-29-2005, 06:31 PM
i am surprised DW didn't catch it. the way i have been staring at my laptop during the last few weeks, it may have and i just didn't see the error ... anyway, thank you again. look for my new site in the review section later this week ... would love feedback from fellow designers ... wynne