How to use the sendmail option on PHP

Posted by kumarjit in The Internet, Web Hosting Tips

1 Star2 Stars (1 votes, average: 0.00 out of 5)

How to use the sendmail option on PHP

Websites often need to send mail to certain user accounts for purposes like email-id verification, sending newsletters and updates, or sending account details. The PHP programming language has the mail() function to send mail to any Email address. It uses the SMTP protocol for sending mail.

Syntax of the sendmail function

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

The variables explained

The variable $to signifies the email address to which the mail is being sent. Some examples are:

The variable $subject supplies the subject of the email sent .

The string $message contains the entire body of the message.

$additional_headers is used to supply additional headers with the mail, for example the from header, or the Reply-To header. The headers are seperated with CRLF ( carriage-return linefeed ) sequences.

Example

An example use of the sendmail function –

$to = ”abc@example.com”;

$subject = ”testing”;

$message = “hello world!”;

$headers = “From: webmaster@example.com” . “\r\n” . “Reply-To: webmaster@example.com”;

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

BounceWeb provides great deals on PHP web hosting!


Be Sociable, Share!

Leave a Reply

You must be logged in to post a comment.