stbalaji2u Posted August 21, 2008 Share Posted August 21, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/120729-what-is-the-use-of-headers-here/ Share on other sites More sharing options...
JonnoTheDev Posted August 21, 2008 Share Posted August 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/120729-what-is-the-use-of-headers-here/#findComment-622136 Share on other sites More sharing options...
uniflare Posted August 21, 2008 Share Posted August 21, 2008 Also certain headers are required when sending to servers like hotmail, otherwise your email could end up in Junk or Spam even if it is completely clean. Quote Link to comment https://forums.phpfreaks.com/topic/120729-what-is-the-use-of-headers-here/#findComment-622158 Share on other sites More sharing options...
Prismatic Posted August 21, 2008 Share Posted August 21, 2008 You can append a variable using .= For example, $var = "hello "; $var = "world"; echo $var; Will output "world" However, using .= $var = "hello "; $var .= "world"; echo $var; Will output "hello world" Quote Link to comment https://forums.phpfreaks.com/topic/120729-what-is-the-use-of-headers-here/#findComment-622160 Share on other sites More sharing options...
stbalaji2u Posted August 22, 2008 Author Share Posted August 22, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/120729-what-is-the-use-of-headers-here/#findComment-622894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.