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("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";
    }
?>
No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

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

The reCAPTCHA verification period has expired. Please reload the page.