In a site or a webapp the capability to send an email is a must have. The PHP language is a very complete language and provides a lot of functions to simplify your devloping.

Inside the tons of functions provided by the PHP language (both versions 4 and 5) you can find also a dedicated function to send an email.

Naturally this function is the "mail()" function.

Let's give a look to this function:

 

 

 

 

 

SINOPSYS

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

The "to" parameter must comply to RFC2822 (i.e. user@example.com[, anotheruser@example.com])

The mail() function returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

A simple example could be useful:

<?php

 $to = "user@example.com";
 $subject = "Subject of the email";
 $body = "Body of the email\n\non another line";
 if (mail($to, $subject, $body)) {
   echo("<p>Message successfully sent!</p>");
  } else {
   echo("<p>Message delivery failed…</p>");
  }
 ?>
 
That's all.


gg1