Reputation: 3628
Alright I'm sure I'm doing something wrong here but I cannot for the life of get these PHP variables to display inline!
EDIT: This is what the code looks like now, stil not working.
<?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 = '[email protected]';
$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>
Upvotes: 1
Views: 6960
Reputation: 11
Try to use rtrim on each of the variables before echoing them. Second suggestion is why not generate the complete string in php script as well
$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";
Then simply anywhere you like inside the html portion.
Hope this helps
Upvotes: 1
Reputation: 53606
You have a body sent before header bug (try turning on your error messges). It happens here:
<?php
(line 0)
and
$confirm = 'no';
}
?>
<?php session_start(); ?>
To solve this, make sure you have only one <?php
before the session_start
, that it has no spaces before that, and you do not save the page with BOM.
Upvotes: 2
Reputation: 18305
Perhaps try this style of inline echo instead:
<?php=$name;?>
Or try moving session_start()
up to the very top of your code.
Upvotes: 0