Sending emails using the mail() function


In the following example, we will use the built-in mail() function, where, as parameters, client data will be transmitted via a $_POST request.



if ($_POST['submit'])
 {
  
$from    $_POST['from'];
  
$to      $_POST['to'];
  
$subject $_POST['subj'];
  
$message $_POST['msg'];
  
$headers "From: $fromrn";
  
$headers .= "MIME-Version: 1.0rn";
  
$headers .= "Content-Type: text/plain; charset=windows-1251rn"."Content-Transfer-Encoding: 8bitrn";
  
mail($to"=?windows-1251?B?".base64_encode($subject)."?="$message$headers"-f ".$from);
}
?>