Automatic send email HELP

Discussion in 'PHP' started by black.hat, Oct 17, 2009.

  1. #1
    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?
     
    black.hat, Oct 17, 2009 IP
  2. WarzMX

    WarzMX Active Member

    Messages:
    163
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #2
    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.
     
    WarzMX, Oct 17, 2009 IP
  3. black.hat

    black.hat Active Member

    Messages:
    157
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3

    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?
     
    black.hat, Oct 17, 2009 IP
  4. musicmasteria

    musicmasteria Peon

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?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):
     
    musicmasteria, Oct 18, 2009 IP