简体   繁体   中英

How do I make sure email gets sent only one time per session?

I want to be able to allow visitors to my site to be able to send an email only ONCE per session. I don't want visitors to send emails over and over causing problems.
Is there a way of using session variables to only allow email sending only one time?

I'm using CakePHP 2.x and my email function is simply called email().

Thanks in advance!

If I were you I would create a new session variable once the first email is sent and set it to a string and then write an if statement saying that if the session variable's string length is greater than one, do not send email, else send email. the if would look something like:

if(strlen($_SESSION['mySessionVariable'])>1)

then don't send email

else

send email

Here is the cake php solution from @Tim Mcneal answer.

function sendEmail(){
    if($this->Session->check('EmailSent')){
        //dont send email
    }else{
       //your email sending code
       $this->Session->write('EmailSent', true);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM