PHP mail function

This PHP mail function script has the ability to send a plain text email message. There are much better and more advanced PHP scripts on the Internet, but I hope this example will help you to understand, how it’s possible to send an email message using some PHP code.

php-mail-function

Using mail() to send a simple email:

<?php
mail("[email protected]", "The Subject", "The Message", null, "[email protected]")
?>

Example:

<?php
mail("[email protected]", "Confirmation", "This is a confirmation Mail", null, "[email protected]")
?>

Sending mail with extra headers:

<?php
ini_set('display_errors',true);
error_reporting(E_ALL);
    if (mail("[email protected]", "The Subject", "The Message", null, "[email protected]")) {
        echo "email sent";
    } else {
        echo "email failed";
    }
?>

Example:

<?php
ini_set('display_errors',true);
error_reporting(E_ALL);
    if (mail("[email protected]", "Confirmation", "This is a confirmation Mail", null, "[email protected]")) {
        echo "email sent";
    } else {
        echo "email failed";
    }
?>

Leave a Reply

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.