-3

i am trying to send mail using php. i have removed the comment from the SMTP port and mail but Apache throws undefined variable $header in line no.5. what is wrong here?

<?php include "head.php";?>
<?php
$from= "smechailes@gmail.com";
$Headers = "";
$header .= "MIME-Version: 1.0 \r\n";
$header .= "Content-type: text/html; Charset= iso-859-1 \r\n";
$header .= "From: ".$from." \r\n";
$to = "setok321@gmail.com";
$subject = "test-mail";
$message ="<h1>hello</h1>";
$mail = mail($to, $subject, $message, $header);
echo (int)$mail;
?>
<?php include "foot.php";?>
Oz Thewizard
  • 55
  • 1
  • 6

3 Answers3

2

Replace $Headers = ""; by $header = "";

Explanation:

PHP variables are case sensitive.

You have initialised variable $Headers and assuming it to be $header.

And concatenating to $header, which is undefined.

Either change $Headers to $header

OR

change

$header to $Headers at all places.

Pupil
  • 23,834
  • 6
  • 44
  • 66
1

You are using the concatenating assignment operator when you use .=:

$header .= "MIME-Version: 1.0 \r\n";

is equivalent to:

$header = $header . "MIME-Version: 1.0 \r\n";

Meaning $header is used as a part of the assignment and should exist prior.

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
0

use below code, because on line 5 $header is not defined you are concatenate the string

<?php include "head.php";?>
<?php
$from= "smechailes@gmail.com";
//$Headers = "";
$header = "MIME-Version: 1.0 \r\n";
$header .= "Content-type: text/html; Charset= iso-859-1 \r\n";
$header .= "From: ".$from." \r\n";
$to = "setok321@gmail.com";
$subject = "test-mail";
$message ="<h1>hello</h1>";
$mail = mail($to, $subject, $message, $header);
echo (int)$mail;
?>
<?php include "foot.php";?>
karthickeyan
  • 372
  • 2
  • 12