12

I am writing a PHP mail function and some examples have @mail(…) and others have just mail(…).

What is the difference and which one is best to use?

Cheers

1

4 Answers 4

21

@ supresses all warnings/errors, which mail() function may throw.

It is not good practice to use "@", because you never know if something doesn't work and also it hits the performance of you PHP application too!

Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant :) That answered my question perfectly
4

It's the same function but with error suppression

PHP: Error Control Operators - Manual

Comments

3

@mail means you are suppressing any errors that might occur while trying to send the email, see this SO question for more information: Suppress error with @ operator in PHP

1 Comment

Cheers. That answers more of my questions. Thanks for the help
2

Error suppression is resource-consuming operation. It is recommended to call functions without @ and use exceptions/error handling

1 Comment

I would normally use the non-suppressed functions, but I found the @mail in a site I have been maintaining and didn't want to mess with it too much.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.