Page 1 of 1
mail problem
Posted: Thu Nov 21, 2002 5:20 am
by 662Corporation
Hi folks,
I've written the following script but it goes into an endless loop and sends 100s of emails to the given address, can anybody tell me what's wrong with it?
Here's the code:
<?php
$to = "
destination@address.com";
$subject = "subject line";
$body = "<font size=\"2\" face=\"tahoma\">" . $sender_enquiry . "<br><br>" . $sender_name . "<br>" . $sender_company . "<br><br>" . $sender_address ."<br>" . $sender_telephone . "</font>";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $sender_name <$sender_email>\r\n";
mail($to,$subject,$body,$headers);
header("Location: " . $main_url . "?p=contact&action=thankyou");
?>
Posted: Thu Nov 21, 2002 5:42 am
by twigletmac
Is this:
Code: Select all
header("Location: " . $main_url . "?p=contact&action=thankyou");
refreshing the same page? If so is there a test being run which ensures that the mail is not sent again if $_GET['action'] is equal to 'thankyou'?
Mac
Posted: Thu Nov 21, 2002 5:52 am
by 662Corporation
it's not meant to refresh the same page, the file is called contact.php which at no point comes up in the user's address bar
as far as the user can see the whole site is run off the index file using variables in the url eg.
http://domain.com/index.php?p=services or
http://domain.com/?p=contact
the header function above should send the user back to the index file along with the variables p=contact&action=thankyou
the mail function is contained in contact.php which is the action of the form on the contact page, i just basically want them redirected to a thank you page once they've submitted the form
i haven't bothered with any server side validation as it's all done with js before the form is submitted
Posted: Thu Nov 21, 2002 6:06 am
by twigletmac
Would it be possible to see more of the code as there doesn't appear to be anything in the code above that would cause an unending loop. Is contact.php included into index.php? Is all code included into index.php with different variables sent through the URL?
Mac
Posted: Thu Nov 21, 2002 6:15 am
by 662Corporation
basically what happens (or should be happening anyway) is this:
1. user hits contact link and they're sent to
http://domain.com/?p=contact
the form being submitted is included in the index page
2. they fill in the form with js validating it along the way and submit it
3. the form is sent to
http://domain.com/contact.php which should simply just send the email and redirect to the given url
the only other code is the actual form which is using the POST method because the email message could get pretty long and i couldn't put that in the url
the .inc file which contains the form has an arguement in it asking whether action is true or not and just printing different bits of text to the page depending on the result but i can't see why that would be causing the loop
Posted: Thu Nov 21, 2002 7:02 am
by 662Corporation