PHP mail()发送空变量

时间:2013-11-16 16:40:21

标签: php arrays email

我有一个输出数组的验证类($ arr)$validates = Comment::validate($arr);我将该数组用于PHP的邮件功能:$email=$arr['email']; $name=$arr['name']; $message=$arr['comment'];。 邮件发送没有问题,但脚本的行为是变量是空的,但它们不是(我用echo语句测试了它)。但$name=$_POST['name'];等工作正常。有什么建议为什么会发生这种情况?这是代码的一部分。

$validates = Comment::validate($arr); // validate and fetch data, can be either TRUE or FALSE (1 or 0)


// ------------- CONFIGURABLE SECTION ------------------------
$mailto = 'email@bla.de'; // set to the email address you want the form sent to
$subject = "Feedback Form"; // $subject - set to the Subject line of the email
$formurl = "feedback.html" ;
$errorurl = "feedback_error.php" ;
$thankyouurl = "feedback_thankyou.php" ;
$uself = 0;
$email = $arr['email'];
$name = $arr['name'];
$message = $arr['comment'];
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n"); // \n Line Feed, \r Carriage Return

$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: Sender Name <sender@domain.com>";
$headers[] = "Bcc: JJ Chong <bcc@domain2.com>";
$headers[] = "Reply-To: Recipient Name <receiver@domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();


// -------------------- END OF CONFIGURABLE SECTION ---------------

$http_referrer = getenv( "HTTP_REFERER" );
$js_enabled = $_POST['js_enabled'];

//--------------------------------------------------------
if($validates) {
//echo 'message: '.$message; <-- this works (it's not empty)

$msg = array();
$msg[] = "Nachricht von: ".$http_referrer;
$msg[] = "Name des Absenders: ".$name;
$msg[] = "E-Mail des Absenders: ".$email;
$msg[] = "------------------------- Nachricht -------------------------";
$msg[] = $message; // <-- this is not working ??? ($message=$_POST['comment']; works just fine)
$msg[] = "--------------------------------------------------------------";

mail($mailto, $subject, implode("\r\n",$msg), implode("\r\n",$headers));


// THANK YOU URL 
if ($js_enabled == '0') { // IF NO jAVASCRIPT
    header("Location: $thankyouurl"); 
    exit; 
} // ELSE AJAX REQUEST
echo json_encode(array('status'=>1));
// echo '{"status":1}';
} else { // ERROR URL 
    if ($js_enabled == '0') { // IF NO jAVASCRIPT 
        $err = serialize($arr);
        $err_url = urlencode($err);
        header("Location: $errorurl?errors=$err_url"); exit; 
    } // ELSE AJAX REQUEST
    echo '{"status":0,"errors":'.json_encode($arr).'}';
}

1 个答案:

答案 0 :(得分:0)

你有没有初始化$arr?看起来您希望它与$_POST相同,但我在您的代码中看不到对$_POST的引用。