Networking, Programming and Graphics Tutorials

Use PHP to send email from web applications [2/3]

PHP mail() function offer some parameters. Function will return true on success and false on fail. Parameter $headers is not obligate. The main format of mail() function is:

<?php
$send_mail 
mail($to$subject$message$headers);
?>
All of this we can put in one PHP function for more functionality and clear code.
Variable $to is used for specifying address on which we want to send e-mails.
Variable $subject is used for specifying subject of e-mails.
Variable $headers is used for specifying headers of e-mails.[Not required]

<?php
function send_mail($from_name$from_email$message) {

    
// on which e-mail must send messages
    
$to "contact@mysite.com";

    
// subject of the message
    
$subject "Message from Mysite.com";

    
// headers for setting From: and Reply-To:
    
$headers .= "From: $from_name <$from_email>\n";
    
$headers .= "Reply-To: $from_name <$from_email>\n";

    
// try to send mail
    
$send_mail mail($to$subject$message$headers);

    
// check and return result
    
if ($send_mail) {
        return 
true;
    } else {
        return 
false;
    }
}
?>
Networking, Programming and Graphics Tutorials - Use PHP to send email from web applications [2/3] - Networking, Programming and Graphics Tutorials

Need a specific tutorial? Do not hesitate and submit a request!
Related Tags: how to send email php  send email to many with php  send email to many php  php email send value in message  send email to many people with php  send content value+php email function  email send button php script  SIMPLE APPLICATIONS OF SPLINES  applications that need administrator accounts in windows xp  guest account can access applications