What are some best practices for sending confirmation emails to new members in PHP applications?

When sending confirmation emails to new members in PHP applications, it is important to ensure that the email is clear, personalized, and includes all necessary information for the user to confirm their account. This can help reduce the chances of the email being marked as spam and increase the likelihood of the user completing the confirmation process.

// Send confirmation email to new member
$to = $new_member_email;
$subject = 'Confirm Your Account';
$message = 'Dear ' . $new_member_name . ', thank you for signing up! Please click the following link to confirm your account: http://yourwebsite.com/confirm.php?token=' . $confirmation_token;
$headers = 'From: yourwebsite@example.com' . "\r\n" .
    'Reply-To: yourwebsite@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

if($mail_sent) {
    echo 'Confirmation email sent successfully!';
} else {
    echo 'Failed to send confirmation email. Please try again.';
}