What best practice is recommended in the forum thread to ensure emails are only sent under specific conditions?

To ensure emails are only sent under specific conditions, the best practice recommended in the forum thread is to use an if statement to check the conditions before sending the email. This way, the email will only be sent when the specified conditions are met.

if ($condition1 && $condition2) {
    // Send email code here
    mail($to, $subject, $message);
}