Monday 22 April 2013

PHP E-mails


PHP Sending E-mails

PHP allows you to send e-mails directly from a script.


The PHP mail() Function

The PHP mail() function is used to send emails from inside a script.

Syntax

mail(to,subject,message,headers,parameters)


Requirements

For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file.


Installation

The mail functions are part of the PHP core. There is no installation needed to use these functions.


Runtime Configuration

The behavior of the mail functions is affected by settings in the php.ini file.


PHP Simple E-Mail

The simplest way to send an email with PHP is to send a text email.
In the example below we first declare the variables ($to, $subject, $message, $from, $headers), then we use the variables in the mail() function to send an e-mail:

<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More