PHP E-mail

PHP allows you to send e-mails directly from a script. The PHP mail() function is used to send emails from inside a script.

Syntax

mail($to, $subject, $message, $headers);

As you can see above, the mail function has four parameters.

* $to – the recipients email address
* $subject – the subject of the email.
* $message – the email message to be sent.
* $headers – the header contains information such as the format of the email (plain text or HTML), senders name and email, reply to address, CC and BCC.

PHP Simple E-Mail

The following code will send out a plain text email using the PHP built in mail() function.

<?php
$to = "recpeient@domain.com";
$subject = "Test mail";
$message = "Hai! This is a simple plain text message.";
$from = "youraddress@domain.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Posted in Php