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

Gumbo
  • 643,351
  • 109
  • 780
  • 844
Designer023
  • 1,902
  • 1
  • 26
  • 43
  • Also see http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php – Gordon Oct 29 '10 at 10:29

4 Answers4

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!

Laimoncijus
  • 8,615
  • 10
  • 58
  • 81
4

It's the same function but with error suppression

PHP: Error Control Operators - Manual

piddl0r
  • 2,431
  • 2
  • 23
  • 35
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

Community
  • 1
  • 1
Kristoffer Sall-Storgaard
  • 10,576
  • 5
  • 36
  • 46
2

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

user449296
  • 21
  • 1
  • 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. – Designer023 Sep 16 '10 at 09:08