How can I test PHP mail functionality?

You can use the following code saved into a file with a .php extension to test PHP mail functionality:

IMPORTANT NOTE: We strongly recommend using an SMTP relay that requires authentication. Sending mail through unauthenticated SMTP servers (including the localhost relay on Cloud Sites) can result in delays or undelivered email due to stringent anti-spam filters.

<? $headers = 'From:'; mail('', 'Test email using PHP', 'This is a test email message', $headers, ''); ?>

Or you can use this test code:

<?php $to = ''; $subject = 'Test email using PHP'; $message = 'This is a test email message'; $headers = 'From:' . "\r\n" . 'Reply-To:' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers, ''); ?>

Was this content helpful?

© 2015 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER