2017-07-17 13 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";?> 
相关问题