Keep in touch

you can keep in touch with my all blogs and sites by install this Toolbar...
http://rworldtoolbar.ourtoolbar.com/

Friday, June 27, 2008

Sending E-Mail(s) in PHP

PHP mail() function
E-mails in PHP can be easily sent using the library function 'mail'. This function takes four arguments to send E-mails from a PHP web page and returns 'true' upon successful delivery of Email. The parameters of this function are as follows:
-Recipient E-mail address
-E-mail Subject
-E-mail message (body)
-Headers and additional parameters like the Sender E-mail address
Syntax:
mail( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )

This function returns the boolean value 'True' if the mail is sent successfully, otherwise it returns 'False'.

Example:
To : textbox
From : textbox
Subject : textbox
Message(body) : textbox or textarea
Send : button
Above forms shows how to send email through PHP. And code for the above examples given below, use this code and try it.

Sample PHP Code
//Check whether the submission is made
if(isset($hidSubmit)){
//Declarate the necessary variables
$mail_to=$txtEmailto;
$mail_from=$txtEmailfrm;
$mail_sub=$txtSub;
$mail_mesg=$txtMsg;
//Check for success/failure of delivery
if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
echo "E-mail has been sent successfully from $mail_sub to $mail_to";
else
echo "Failed to send the E-mail from $mail_sub to $mail_to";
}
?>

No comments: