My apologies if I misstate something or use an incorrect term. But I was trying to figure out how to use an if statement on an object.
This works just fine and as I understand it, the @ suppresses errors.
if (@mail("$receiver_email", "$subject", "$message", "$headers")) { }
However If I do this it fails:
if (@$mail->send('email@gmail.com', "$receiver_email", "$subject", "$message")) {}
The irony is that the email goes through but the IF fails. How can I fix the IF statement so it works properly?
First of all, don’t use
@. It’s bad practice and better dealt with using error handling routines; see also: Error logging, in a smooth wayFrom your code I can only guess that your code is like this:
If the function doesn’t have a return value, it defaults to
nulland that evaluates tofalsewhich is why the IF “fails”.You should return a success value from your
send()method.