How do I test the PHP mail() function for sending emails?

Последна промяна: 15.10.2025 09:03

To use the PHP mail() function, ensure either the "To" or "From" email address is an active email account created in your hosting account. Below is a sample script to test the function:

";
$to = "info@clientdomain.com";
$subject = "Test Email";
$body = "This is a test message.";

if (mail($to, $subject, $body, $from)) {
 echo "Email sent successfully to: $to";
} else {
 echo "Email sending failed.";
}
?>

Replace test@example.com and info@clientdomain.com with your actual email addresses. Ensure your script is correctly configured to avoid delivery issues.