PHP mail function

Share It!

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("to@example.com", "The Subject", "The Message", null, "-from@example.com")
?>

Example:

<?php
mail("dennis.r@techoism.com", "Confirmation", "This is a confirmation Mail", null, "-fme@mydomain.com")
?>

Sending mail with extra headers:

<?php
ini_set('display_errors',true);
error_reporting(E_ALL);
    if (mail("to@example.com", "The Subject", "The Message", null, "-from@example.com")) {
        echo "email sent";
    } else {
        echo "email failed";
    }
?>

Example:

<?php
ini_set('display_errors',true);
error_reporting(E_ALL);
    if (mail("dennis.r@techoism.com", "Confirmation", "This is a confirmation Mail", null, "-fme@mydomain.com")) {
        echo "email sent";
    } else {
        echo "email failed";
    }
?>

Leave a Reply

Your email address will not be published.