Php Simple E-mail Script


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

Syntax:

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

Params Required Explaination of parameters
to Yes  Reciever's email address
subject Yes Specifies the subject of the email.
message Yes  Message to be sent. Each line should be separated with a (\n). Lines should not longer than 70 characters
headers No Additional headers, like From, Cc, and Bcc. The additional headers should be separated with  (\r\n)
parameters No  Specifies an additional parameter to the sendmail program

Note: PHP requires an installed  email system ro work email system. It is defined in the configuration settings in the php.ini file. Click to View The configuration of mail()

Example :

The simplest example to send an email with PHP.
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.";

?>


Click to view Script for Sending email with multiple attachement 

No comments: