What is the difference between the function calls “mail()” and “@mail()”?
Asked Answered
I

4

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

Intussuscept answered 16/9, 2010 at 8:42 Comment(1)
Also see #3737639Radiochemistry
V
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!

Veterinary answered 16/9, 2010 at 8:45 Comment(1)
Brilliant :) That answered my question perfectlyIntussuscept
S
4

It's the same function but with error suppression

PHP: Error Control Operators - Manual

Sldney answered 16/9, 2010 at 8:46 Comment(0)
A
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

Asiatic answered 16/9, 2010 at 8:46 Comment(1)
Cheers. That answers more of my questions. Thanks for the helpIntussuscept
H
2

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

Helvellyn answered 16/9, 2010 at 9:2 Comment(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.Intussuscept

© 2022 - 2024 — McMap. All rights reserved.