Networking, Programming and Graphics Tutorials

How to Send Email from a PHP Script [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 - How to Send Email from a PHP Script [2/3] - Networking, Programming and Graphics Tutorials

Need a specific tutorial? Do not hesitate and submit a request!
Related Tags: send email on web php  "PHP how to send email"  "send email from web"  how to send email  how to send email php  plesk send mail php script  email troubleshooting  php email PHP_SELF  cc proxy,how to set up email  php email mysql query  general email troubleshooting  setup email on ccproxy  function email($from, $from_name, $to, $message)  ccproxy email server configuration  thunderbird internet-email-account how-to  setup bt email for outlook 2003  new email account microsoft office outlook  unicef email account port number  internet and email risks - cookies and spam  microsoft office 2003 email setup