My Form processor is broke... ( 4 Views )
-
I have a simple feedback form:
Code:
<form action="<?php echo $PHP_SELF; ?>" method="post" name="contact" id="contact" onsubmit="YY_checkform('contact','fullname','#q','0','Please enter your correct full name','email','#S','2','Please enter a valid email address.','location','#q','0','Please enter your location, e.g. Sydney. Australia.');return document.MM_returnValue">
And the php is on the same page below the form (see below). Could someone please have a look at this code and suggest why it won't work?
Thks
Martin
Code:
<?php
//Feedback form processing. Check if form submitted by checking for the variable in the hidden field.
$submitted = $_POST['submitted']; //Retrieves the hidden form field and sets it to a variable
if ($submitted) {
$name = $_POST['name']; //Retrieves the form name field and sets senders name to a varible
$from = $_POST['email']; //Retrieves the form email field and sets senders email to a variable
$location = $_POST['location']; //Retrieves the form location field and sets location to a variable
$subject = $_POST['subject']; //Retrieves the form subject field and sets subject to a variable
$message = $_POST['message']; //Retrieves the form message field and sets senders message to a variable
$headers .= "From: $name\n";// Name of sender
$headers .= "Return-Path: <webmaster@mysite.net>\n"; //Return bounced emails to.
$headers .= "X-Priority: 2\n"; //Message priority is set to (not so) HIGH
$headers .= "X-MSMail-Priority: High\n"; //Message Priority for Exchange Servers
$headers .= "Disposition-Notification-To: contact@mysite.net>\n"; //Read receipt
$headers .= "X-Mailer: PHP(".$_SERVER['REMOTE_ADDR'].")\n"; //IP address of who sent the mail.
$email = "contact@mysite.net"; // Recipients address
// Email body
$fullmessage .="Greetings!\n\n";
$fullmessage .= "A visitor called $name has just sent a message from the Nitramedia Contact form.\n\n";
$fullmessage .= "Details are:\n";
$fullmessage .= "Name: $name,\nEmail: $from,\nLocation: $location,\nSubject: $subject,\nMessage: $message.\n\n";
$fullmessage .= "Regards\n";
$fullmessage .= "Webmaster, Mysite.net.\n";
//send the email
mail($email, $subject, $fullmessage, $headers);
//display message
echo "<p class='greentext'><strong>Thankyou, your message has been sent.</strong></p>";
}
?>
(beyza, Chile)
Are you getting errors or is it not sending the email?
(nedim, Switzerland)
No errors and no email.
Can I put some code in there somewhere to pick up a problem?
(mehmet vefa yılmaz, Saint Helena)
first off i would change the last few lines to this...
PHP Code:
if(@mail($email, $subject, $fullmessage, $headers))
{
//display message
echo "<p class='greentext'><strong>Thankyou, your message has been sent.</strong></p>";
}
(ahmet, Cook Islands)
Just guessing, your server may require a valid from address?
$headers = "From: " . $name ." <" . $from . ">\n";
(baran, Lebanon)
No joy I'm afraid.....still no email and no errors either, which doesn't help.
(erhan, Romania)
Have you successfully been able to use the mail() function previously on your server?
If not, your problem might lie in the version of PHP you are working on.
Older versions require...
PHP Code:
$HTTP_POST_VARS['fieldname'];
//Rather than...
$_POST['fieldname'];
The problem you are having sounds like this might be the case. Try to change it to this...
PHP Code:
//Feedback form processing. Check if form submitted by checking for the variable in the hidden field.
$submitted = $HTTP_POST_VARS['submitted']; //Retrieves the hidden form field and sets it to a variable
if ($submitted) {
$name = $HTTP_POST_VARS['name']; //Retrieves the form name field and sets senders name to a varible
$from = $HTTP_POST_VARS['email']; //Retrieves the form email field and sets senders email to a variable
$location = $HTTP_POST_VARS['location']; //Retrieves the form location field and sets location to a variable
$subject = $HTTP_POST_VARS['subject']; //Retrieves the form subject field and sets subject to a variable
$message = $HTTP_POST_VARS['message']; //Retrieves the form message field and sets senders message to a variable
(ismail, Netherlands Antilles)
Ok, I'll admit right up front that I'm completely stupid....... :o
All the while I was looking for a problem with the php which seemed ok to me and the problem was a much simpler one - i had a misnamed a form field and had no value for my hidden field upon which the whole thing hinged! (Doh)
Sry to waste your time, but its nice when it all finally works! :-)
Thks.
M.
(ferhat, French Polynesia)
Doh!! I hate when that happens too... takes hours sometimes to find it huh... just a technique i use when things dont work right is to echo out all the variables and/or actions taken to see what is actually going on.
(asmin, Heard Island and Mcdonald Islands)
Related Topics ... (or search in 1.720.883 topics !)
calculator form broke now under php 5 (2) form processor (4) looking for a form processor... (3) form processor (2) need form processor help (2) what's the best form processor? (10) form mail processor (2) php form processor.. (10) asp form processor (3)
copyright © 2007-2031 Pfodere.COM ( 7 Pfoyihuee Online )
|