开发者

Require_once triggering on page load and when submit?

I have a php page (horses.php) that includes:

 <?php require_once('send_email.php');?>

What happens is I have some scripting to send an email (and do some other things) in the send_email.php file.

Now when horses.php loads the send_email.php page triggers and sends an email. It works perfectly. But on horses.php I also have a submit button that updates a开发者_开发问答 db and goes to anoher page.. But what happens is that the send_email.php seems to be triggered on page load and also on submit? Because I get an email on page load (as I should), but then also when I press submit??

Ideas around this?

Thanks


You could try only sending the email if the form hasn't been submitted:

if (!isset($_POST['name_of_an_element_in_the_form'])) {
  require_once('send_email.php');
}


You have some code to send a mail while loading send_email.php ? I don't think it's a good practice, just define a function (or a class) to send a mail in send_email.php and call it when you actually need to send a mail...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜