I wanna code to send an e-mail automatically when the page loaded, and it must work per session, for example if somebody visited that page, it must send the email only 1 time, and if the visitor refreshed that page it will not send the email again. Can somebody help?
Hi, I made this code for you, should be something like this, hope that helps. <?php session_start(); if (!($_SESSION['mail'])) { $_SESSION['mail'] = true; mail(to,subject,message,headers,parameters) } ?> Code (markup): When user first comes to your page there will be no session variable created... that means you can send mail and create a session variable. If user refresh the session variable will already be created and then no e-mail will be sent.
Well thanks but Its showing this error: Parse error: syntax error, unexpected '}' in /home/xxx/public_html/mail.php on line 8 also where i should enter my email address to receive the email?
<?php session_start(); if (!($_SESSION['mail'])) { $_SESSION['mail'] = true; mail(to,subject,message,headers,parameters); //he forgot the ";" } ?> Code (markup): And you asked where to enter your email, that's obvious. It is the 'to' parameter. If we take a closer look at the function: mail('sendto@email.com','Email Subject','message goes here','headers go here'); Code (markup): Alternatively you could use variables to define the parameters of the mail() function to allow for dynamic email content (not the same message every time). $to = 'sendto@email.com'; $subject = 'Email Subject'; $message = 'message goes here'; $headers = 'headers go here'; mail($to,$subject,$message,$headers); Code (markup):