SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mail function error

    Hi,

    While sending mail from server i am getting the following error.

    Warning: mail() [function.mail]: SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in C:\Inetpub\vhosts\xxx\signup_success.php on line 70 Email-id that you have registered is not valid.
    This is because of wrong Email-id / server settings. My problem is , i want to hide this error from user's view. How to hide this error mgs .


    My code is here

    PHP Code:
    <?php
    $msg
    =" Hai ";      
    $from "xxx@xxx.com";
    $subject "sample";
    $message $msg;
    $headers "MIME-Version: 1.0" "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" "\r\n";
    $to =  'yyy@yyy.com';
    $headers "From:".$from"\r\n";
    if (
    $_SERVER['REQUEST_METHOD'] == "POST") {
        foreach (
    $_POST as $key => $value) { 
            
    $msg .= ucfirst ($key) ." : "$value "\n"
        }
    }
    else {
        foreach (
    $_GET as $key => $value) { 
            
    $msg .= ucfirst ($key) ." : "$value "\n"
        }
    }
    $sent mail($to,$subject,$msg,$headers);
    ?>
    Some one please give some ideas. Thanks in advance

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using the '@' symbol before the function turns off all error reporting for that function.


    PHP Code:
    @mail(" "" "" "); 
    This would not display the error mail() would generate.

  3. #3
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    biginner, are you sure you want to hide the message, not to send email?

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for reply..

    If its correct mail id , Mail function should work...

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    biginner, are you sure you want to hide the message, not to send email?
    If this is just for testing purposes, just adding the @ would work. For a production script, you may want to add something more..

    Code PHP:
    if (@mail("", "", "")) {
        # email has been sent, continue on.
    } else {
        # mail() has generated an error, instead of killing the
        # remainder of the script, here you can add a custom
        # alert that wont break your page with the generated
        # error.
        echo "There was an error sending your email.";
    }

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @mail() function works... thanks a lot ...

  7. #7
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd suggest to use
    PHP Code:
    ini_set("display_errors",0); 
    instead

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ini_set("display_errors",0);
    Can u plz define this syntax sir ?

    This is only to hide mail function error or all php errors sir ?

  9. #9
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    ini_set("display_errors"0); 
    This would suppress all generated errors throughout the script.

  10. #10
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much for reply.
    here i learned sometning new to solve some errors...

  11. #11
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you use ini_set() I would suggest using some form of checking on every function that could possibly throw an error though.

  12. #12
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But why? There is no relation between error checking and displaying error messages.
    You can check your functions in either case.

    May be I should say it this way:
    PHP Code:
    ini_set("display_errors"0); 
    ini_set("log_errors"1); 

  13. #13
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am developing one shopping site. In signup page , final page i want to send mail conformation to my users. So, here i am getting errors. if the user type wrong mail Id , the above error is displaying. I want hide it and echo "Error";


    ini_set("log_errors", 1);
    What is the use of this function sir ?

  14. #14
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand your mail Id thing.
    you said above it's "server settings"
    now you're talking of user input but I can't see any email id processing in the code.

    ini_set("log_errors", 1); will put all error messages into default webserver's error log, so, you can watch it there and take proper actions, while user won't see anything.

    if you put @ to gag error message, you won't see it if some other error occurred

  15. #15
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since you are wanting to output "Error" on a mail() error, you will need to do it this way

    Code php:
    if (@mail("", "", "")) {
        # email has been sent, continue on.
    } else {
        # mail() has generated an error, instead of killing the
        # remainder of the script, here you can add a custom
        # alert that wont break your page with the generated
        # error.
        echo "There was an error sending your email.";
    }

    The ini_set() function sets configuration options found in your php.ini file. All that the ini_set() would do in this application would suppress the native PHP errors from generating. Running the if/else statement will check if mail() was successful, and if not, display the error message YOU want.

  16. #16
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please look at my first post.
    This is because of wrong Email-id / server settings.
    In my server, I am getting the error bec of these reasons....

  17. #17
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, and this will suppress the "Warning: mail() [function.mail]: SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in C:\Inetpub\vhosts\xxx\signup_success.php on line 70 Email-id that you have registered is not valid." until you have this on a server that will send the message.

  18. #18
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Exactly, this error is causing because of server settings only... Sorry. I have posted wrongly.

  19. #19
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for all.....

  20. #20
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I would advise strongly against using @ for error suppression. It is the equivalent of brushing the errors under a rug and ignoring them, rather than solving the issue that caused the error in the first place.

    Leave errors on for your local development machine, turn them off and log them for the production environment to catch ones you missed otherwise.

  21. #21
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for this suggestion. I cant change the server settings. I dont have that rights, In that situation i have to hide this error. so only , I have posted this forum..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •