Jump to content

What is the use of headers here???


stbalaji2u

Recommended Posts

Hi friends now i wonder what is the use of the header variables here...

i think its just a basic question about the php mail funtion but please solve my doubt coz im learning php mail funtion quite too lately..

Anyway here is the code pls tell what actually header variable which keeps changing its values in evey line is used in this program is this header value is used in anyother hidden part of this code if so what purpose and where shall i be used???

<?php
function send_email($from, $to, $subject, $message){
$headers = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "Return-Path: ".$from."\r\n";
$headers .= "Content-type: text/html\r\n"; 

if (mail($to,$subject,$message,$headers) ) {
   echo "email sent";
} else {
   echo "email couldn't be sent";
}
}

$subject = "Helloooo!";
$message .= "<html><body>";
$message .= "<b>Hey! How are you today?</b>";
$message .= "<br>Regards";
$message .= "</body></html>";
send_email("[email protected]", "[email protected]", 
$subject , 
$message);
?>

Link to comment
https://forums.phpfreaks.com/topic/120729-what-is-the-use-of-headers-here/
Share on other sites

Mail headers are part of the message construct so that a mail agent can display where the message has come from, what type of content it is, the reply address, etc (you must have seen an email in Microsoft Outlooks inbox). Without the headers you may get errors when using the mail() function.

Wow thanks guys for your excellent replies. . well i think now i clearly understand the use of headers now but just storing the values in header variable makes what difference at all ?? because the header is not used in anywhere of the code.is there any other code that needs to append with this code?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.