Contents

PHP tutorials

Introduction

Syntax

Variables

Data Types

Operators

echo

If/Else

Loops

chmod()

mail()

date()

phpinfo()

 

 

mail()

PHP allows webmasters to send e-mails directly from a script, using PHP mail() function.

In the next example we use the mail() function to send an e-mail:

<?php
$to = "recipient@example.com";
$subject = "PHP mail()";
$message = "This is a simple e-mail message.";
$from = "sender@example.com";
mail($to,$subject,$message,$from);
echo "E-mail sent!";
?>

 

The first three parameters are obligatory and represent the address to send e-mail to, the subject line and the message content. The fourth parameter can be used to send any additional valid e-mail headers. In our case we have used the fourth parameter to add a "From:" address for the e-mail.