mail problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
662Corporation
Forum Newbie
Posts: 5
Joined: Thu Nov 21, 2002 5:20 am
Location: Glasgow, UK

mail problem

Post 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");
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Is this:

Code: Select all

header("Location: " . $main_url . "?p=contact&amp;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
662Corporation
Forum Newbie
Posts: 5
Joined: Thu Nov 21, 2002 5:20 am
Location: Glasgow, UK

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
662Corporation
Forum Newbie
Posts: 5
Joined: Thu Nov 21, 2002 5:20 am
Location: Glasgow, UK

Post 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
662Corporation
Forum Newbie
Posts: 5
Joined: Thu Nov 21, 2002 5:20 am
Location: Glasgow, UK

Post by 662Corporation »

:(
Post Reply