Networking, Programming and Graphics Tutorials

Sending e-mails with PHP mail() function [3/3]

What happening when form is sent to web server? Here we need to check that the $send variable is set to 1 and insert PHP code which execute some e-mail function. And now let's see how will look final code of our e-mail form

<?php
// our e-mail function
function send_mail($from_name$from_email$message) {
    
$to "contact@mysite.com";
    
$subject "Message from Mysite.com";
    
$headers .= "From: $from_name <$from_email>\n";
    
$headers .= "Reply-To: $from_name <$from_email>\n";
    
$send_mail mail($to$subject$message$headers);
    if (
$send_mail) {
        return 
true;
    } else {
        return 
false;
    }
}

// check that the form is truly sent
if ($_POST['send'] == 1) {
    
// get data from the form
    
$from_name=$_POST['from_name'];
    
$from_email=$_POST['from_email'];
    
$message=$_POST['message'];

    
// send e-mail
    
$try_mail send_mail($from_name$from_email$message);

    
// output the result
    
if ($try_mail) {
        echo 
"Your e-mail message was sent!";
    } else {
        echo 
"Your e-mail message was not sent!";
    }
}
?>
<html>
<head>
<title>Sending e-mails with PHP mail() function</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="from_name">
    <input type="text" name="from_email">
    <textarea name="message"></text>
    <input type="hidden" name="send" value="1">
    <input type="submit" value="Send">
</form>
</body>
</html>
Rate this tutorial:                    
Networking, Programming and Graphics Tutorials - Sending e-mails with PHP mail() function [3/3] - Networking, Programming and Graphics Tutorials

Need a specific tutorial? Do not hesitate and submit a request!
Related Tags: problem sending mails with php mail function  sending html mails with mail function on php  Mail server+functionality+php+for sending mail receiving mails  php function sending mails on specific date  php mail function many e-mails  mail function php send html mails  php mail function not sending  mail() function not sending  php mail function sending html  mail() function in php for sending files  sending pictures with php mail function  sending mail function PHP windows  sending html with php mail function  sending mail function form php  mail function not sending results  function mail php sending from server  sending picture with mail() function  php sending mails  "sending mails in php"  tutorials on sending form data through php mail function