What specific PHP functions or settings, such as cannonical_mail, can be used to address email sending issues in PHP scripts?

When sending emails using PHP scripts, it's important to ensure that the email headers are correctly set to prevent them from being marked as spam or rejected by the recipient's email server. One common issue is setting the "From" address to a domain that doesn't match the sending server, causing authentication failures. To address this, you can use the `canonical_mail` function in PHP to set the "From" address to a valid email address on the sending server's domain.

// Set the "From" address using the canonical_mail function
$from = canonical_mail('valid@example.com');

// Set additional headers
$headers = 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: ' . $from . "\r\n";

// Send the email
$subject = 'Test Email';
$message = 'This is a test email sent from PHP.';
$to = 'recipient@example.com';

// Send the email
mail($to, $subject, $message, $headers);