Jump to content

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("youraddress@domain.com", "recpeient@domain.com", 
$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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.