Send mail function sends many times

Discussion in 'PHP' started by ASTRAPI, Nov 4, 2008.

  1. #1
    Hi

    I am trying to add a function to a php file and when a user access it to send me a mail with some info but i get the mail 15 times at once :(

    Is is anyway to limit to one?
    Or everytime that i change directory or server to send mail only once?

    This is the code that i add at the top of the rest of the code in the file:

    $to_mail = 'mymail@hotmail.com';
    $subject = 'hello';
    $message = $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . 'was accessed by IP address ' . $_SERVER['REMOTE_ADDR'] . 'on' . date("F j, Y, g:i a") . '!!';
    $from_mail = 'webmaster@server.com';
    
    @mail($to_mail, $subject, $message, "From: $from_mail");
    PHP:

    Maybe the rest code of the file (huge) reload the page or something and i get it 15 times?
    Is there any solution?


    Thanks
     
    ASTRAPI, Nov 4, 2008 IP
  2. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #2
    The code posted should only send once. I would suspect it's something else in the file you didn't post. On a side note, I recommend taking off the @, as it may be suppressing some important errors.
     
    Louis11, Nov 4, 2008 IP
  3. ASTRAPI

    ASTRAPI Guest

    Messages:
    500
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wich @ do you mean?
     
    ASTRAPI, Nov 4, 2008 IP
  4. Bind

    Bind Peon

    Messages:
    70
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    somewhere in your script execution its calling that or another mail send function multiple times.

    if you have a redirect on a successful mail send, it might be loading the same thing over and over again in your logic.

    post ALL the source code and we might be able to help.
     
    Bind, Nov 5, 2008 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    @mail. Putting a @ in front of function hides the error message (if any)

    By the way, that's the only codes in your file? If not show us the whole content of your php file
     
    ads2help, Nov 5, 2008 IP
  6. money4leads

    money4leads Well-Known Member

    Messages:
    117
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #6
    add if may help here !

    if(@mail($to_mail, $subject, $message, "From: $from_mail"))
    {
    //redirect visitor to page1
    }
    else
    {
    //redirect visitor to page2
    }
     
    money4leads, Nov 5, 2008 IP
  7. SEOAnalytic.com

    SEOAnalytic.com Member

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #7
    I think you try to send mail in a loop.
    People here cannot help you if you provide just chunks of code.
     
    SEOAnalytic.com, Nov 5, 2008 IP