I have seen the mail function preceded with an @ symbol. I have tried it in my code and I cannot see what difference it makes.

I have searched Google and the PHP documentation and I have not been able to find an explanation for this @ symbol.

Would someone kindly point me in th right direction please?

It is used to suppress errors. Even if function fails, it continues execution. But we should avoid using it, let the error shown and fix it.

Member Avatar for rajarajan2017

Also if you want to check whether the mail sent commands you can stored in a variable of mail function with the @ symbol

$mail_sent = @mail( $to, $subject, $message, $headers ); 
echo $mail_sent ? "Mail sent" : "Mail failed";

or

if (mail( $to, $subject, $message, $headers ))
   echo "Mail sent";
else
   echo "Mail failed";

Thanks guys ... I asked the question out of curiosity and your answers have made me realise that this is really quite relevent to the code I'm having problems with.

Thank you very much,

Simon.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.