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
$msg=" Hai ";	  
$from = "xxx@xxx.com";
$subject = "sample";
$message = $msg;
$headers = "MIME-Version: 1.0" . "\\r\
";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\\r\
";
$to =  'yyy@yyy.com';
$headers = "From:".$from. "\\r\
";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
	foreach ($_POST as $key => $value) { 
		$msg .= ucfirst ($key) ." : ". $value . "\
"; 
	}
}
else {
	foreach ($_GET as $key => $value) { 
		$msg .= ucfirst ($key) ." : ". $value . "\
"; 
	}
}
$sent = mail($to,$subject,$msg,$headers);
?>

Some one please give some ideas. Thanks in advance

Using the ‘@’ symbol before the function turns off all error reporting for that function.


@mail(" ", " ", " ");

This would not display the error mail() would generate.

biginner, are you sure you want to hide the message, not to send email?

Thanks for reply…

If its correct mail id , Mail function should work…

If this is just for testing purposes, just adding the @ would work. For a production script, you may want to add something more…


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.";
} 

@mail() function works… thanks a lot …

I’d suggest to use

ini_set("display_errors",0);

instead

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 ?

ini_set("display_errors", 0);

This would suppress all generated errors throughout the script.

thank you very much for reply.
here i learned sometning new to solve some errors…

if you use ini_set() I would suggest using some form of checking on every function that could possibly throw an error though.

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:

ini_set("display_errors", 0); 
ini_set("log_errors", 1); 

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 ?

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

Since you are wanting to output “Error” on a mail() error, you will need to do it this way


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.

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…

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.

Exactly, this error is causing because of server settings only… Sorry. I have posted wrongly.

thanks for all…

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.