2017-07-17 84 views
-3

我想用php發送郵件。我已經從SMTP端口和郵件中刪除了註釋,但是Apache在第5行中拋出了未定義的變量$ header。這裏有什麼問題?

<?php include "head.php";?> 
<?php 
$from= "[email protected]"; 
$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 = "[email protected]"; 
$subject = "test-mail"; 
$message ="<h1>hello</h1>"; 
$mail = mail($to, $subject, $message, $header); 
echo (int)$mail; 
?> 
<?php include "foot.php";?> 
+5

已宣佈$頭=「」串;但是使用$ headers – Exprator

+1

它實際上是$ header,因此不管大小寫如何,它都不匹配。 – Devon

+0

使$ Headers成爲$標頭。 –

回答

2

通過$header = "";

說明更換$Headers = "";

PHP變量是區分大小寫的。

您已初始化變量$Headers並假設它是$header

並連接到$header,這是未定義的。

要麼改變,在所有的地方$Headers$header

OR

變化

$header$Headers

+0

你應該發表評論 – Exprator

0

您正在使用連接賦值運算符時使用.=

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

等同於:

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

意義$頭作爲分配的一部分,之前應該存在。

0

使用下面的代碼,因爲在第5行$頭沒有被定義你是串連

<?php include "head.php";?> 
<?php 
$from= "[email protected]"; 
//$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 = "[email protected]"; 
$subject = "test-mail"; 
$message ="<h1>hello</h1>"; 
$mail = mail($to, $subject, $message, $header); 
echo (int)$mail; 
?> 
<?php include "foot.php";?> 
相關問題