PHP Echo没有显示

时间:2011-05-12 00:14:32

标签: php variables echo

好吧我确定我在这里做错了但是我不能让这些PHP变量显示内联的生活!

编辑:这就是代码现在的样子,但是没有用。

<?php
ini_set('display_errors', true); error_reporting(E_ALL);
//declare variables
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
$date = $_POST['date'];
$time = $_POST['time'];
$company = 'Test company';
$dateraw = $date;

$confirmText = "Thank you " . $name . " for booking your appointment with us. We look forward to seeing you at " .$time . " on " . $dateraw . ". You will receive a confirmation email shortly.";

//strip of invalid chars
$date = str_replace( '/' , '.' , $date);

//fopen
$pathToMe = dirname(__FILE__);
$fileName = $pathToMe . "/days/" . $date . ".txt";
$fileHandle = fopen($fileName, 'w') or die("Failure.");
fwrite($fileHandle, $name . "\n" . $email . "\n" . $phone . "\n" . $date . "\n" . $time . "\n" . $comments . "\n" . "\n" ); 
fclose($fileHandle);

//email to company
$to = 'peter@pkazz.com';
$subject = 'Apointment scheduled online';
$body = "An apointment was just scheduled online.\n" . $name . "\n" . $email . "\n" . $phone . "\n" . $date . "\n" . $time . "\n" . $comments . "\n" . "\n" . "Please follow up to confirm.";
if (mail($to, $subject, $body)) {
    $companyConfirm = 'yes';
} else {
    $companyConfirm = 'no';
}

//client confirm
$to = $email;
$subject = 'Confirming your appointment';
$body = "Hello " . $name . "," . "\n" . "\n"  . "You recently booked an appointment with " . $company . " on " . $date . " at " . $time . ".\n" . "\n" . "We will follow up soon to confirm.";
if (mail ($to, $subject, $body)) {
    $confirm = 'yes';
} else {
    $confirm = 'no';
}

print_r($_POST);


?>



<html>
    <head>

    </head>
    <body>

        <div id="jqt">

            <div id="home" class="current">
                <div class="toolbar">
                    <h1>Scheduler</h1>
                </div>
                    <ul class="edit rounded">
                       <li><?php echo $confirmText; ?></li>
                    </ul>
            </div>
            </div>
            </div>
    </body>
</html>

3 个答案:

答案 0 :(得分:2)

你在标题错误之前发送了一个正文(尝试打开你的错误消息)。它发生在这里: <?php(第0行)

   $confirm = 'no';
}
?>

<?php session_start(); ?>

要解决此问题,请确保在<?php之前一个session_start,之前它没有空格,并且您不会使用{保存页面{3}}

答案 1 :(得分:1)

尝试在回显之前对每个变量使用rtrim。第二个建议是为什么不在PHP脚本中生成完整的字符串

$display_message = "Thank you".$name."for booking your appointment with us. We look forward to seeing you at".$time."on".$dateraw."You will receive a confirmation email shortly";

然后在html部分内的任何地方。

希望这有帮助

答案 2 :(得分:0)

或许尝试这种内联回声:

<?php=$name;?>

或者尝试将session_start()移到代码的最顶层。