I've been reading up on the Heredoc and Nowdoc syntax, and I'm trying to understanding how to break out of it so I can add other functionality.
I would like to break out of it after this part (if possible):
User::sendNewticket($send_to, 'Maintenance Ticket '.Input::get('st_id'),
but throws a syntax error when I add ?>
after 'Maintenance Ticket '.Input::get('st_id'), ?>
Anyways, I gave up on that for the time being and I would be good to go if I could figure out how to echo the following using this syntax:
'.$fn.'<br>
'.$time.'<br>
'.$stc.'<br>
Similar to this echo $fn;
Here is relevant code to my situation.
<?php
include($_SERVER['DOCUMENT_ROOT'] . "/core/init.php");
// new data
$send_to = $_POST['send_to'];
$rec_message = $_POST['rec_message'];
//Message
$status = $_POST['status'];
$st_id = $_POST['st_id'];
$posted_by = $_POST['posted_by'];
$posted_on = $_POST['posted_on'];
$unit = $_POST['unit'];
$subject = $_POST['subject'];
$content = $_POST['content'];
//Loader & Flash Message
echo '<meta http-equiv="refresh" content="5;URL=/admin/maintenance/email-ticket.php?st_id='.$st_id.'">';
Session::flash('email-ticket', '<h3 class="orange-tx" align="center">Your Email has been sent!</h3>');
//Replies
//$id = $_POST['id'];
//$from_name = $_POST['from_name'];
//$st_time = $_POST['st_time'];
//$st_content = $_POST['st_content'];
//Pulling Conversation from database
$st_messages = DB::getInstance()->query("SELECT `id`,`st_id`,`from_name`,`st_content`,`st_time` FROM `st_messages` WHERE `st_id` = $st_id ORDER BY id ASC");
foreach ($st_messages->results() as $mt) {
if($mt->from_name=='Support Team'){
} else {
}
$fn = escape ($mt->from_name);
$time = escape (date("F d, Y - h:i a", strtotime ($mt->st_time)));
$stc = nl2br (escape($mt->st_content));
//START EMAIL
User::sendNewticket($send_to, 'Maintenance Ticket '.Input::get('st_id'),
'Hello -<br><br>
'.Input::get('rec_message').'<br><br>
<strong>Ticket Info:</strong><br><br>
<strong>Status: </strong>'.Input::get('status').'<br>
<strong>Ticket #: </strong>'.Input::get('st_id').'<br>
<strong>Posted By: </strong>'.Input::get('posted_by').'<br>
<strong>Posted On: </strong>'.Input::get('posted_on').'<br>
<strong>Building Unit: </strong>'.Input::get('unit').'<br>
<strong>Subject: </strong>'.Input::get('subject').'<br>
<strong>Ticket Message: </strong>'.Input::get('content').'<br><br>
<strong>Conversation:</strong><br><br>
'.$fn.'<br>
'.$time.'<br>
'.$stc.'<br>
---------------------------------<br><br>
Thank You,<br>
Support Team');
}
?>
What I'm trying to do is email a support ticket conversation to one recipient. Like this:
I'm getting the "Original Message" from the Message $_POST. And the email address and email message from the New Data $_POST.
For the Conversation I'm trying to pull that info from the database table.
My current code emails the conversation, but emails each conversation in multiple emails.
Example, If there are 3 entries in the conversation it sends 3 emails:
- Email 1 contains: Admin reply 1
- Email 2 contains: User reply 1
- Email 3 contains: Admin reply 2
I think if I get the echo working it will group the entire conversation into one email.
This is an example of the final email output I trying to obtain:
Hello -
Hey Please view this ticket and take care of the problem. Thanks
Ticket Info:
- Status: OPEN
- Ticket #: 201406016
- Posted By: User Name
- Posted On: June 27, 2014 - 03:46 pm
- Building Unit: D47
- Subject: 1
- Ticket Message: 1
Conversation:
Support Team
July 01, 2014 - 09:19 am
Admin reply 1
User Name
July 01, 2014 - 09:19 am
User reply 1
Support Team
July 01, 2014 - 09:19 am
Admin reply 2
Thank You,
Support Team
END Email Example
Any suggestions would be helpful.
UPDATE
I'm starting to understand this a little better. The only error I'm receiving is in my foreach loop not sure how to correct it.
Here is the code:
$st_messages = DB::getInstance()->query("SELECT `id`,`st_id`,`from_name`,`st_content`,`st_time` FROM `st_messages` WHERE `st_id` = $st_id ORDER BY id ASC");
//START EMAIL
$recMessage = Input::get('rec_message');
User::sendNewticket($send_to, 'Maintenance Ticket '.Input::get('st_id'), <<<TEXT
Hello -<br><br>
$recMessage
TEXT
foreach ($st_messages->results() as $mt) {
$fn = "echo escape ($mt->from_name);";
$time = "echo escape (date(\"F d, Y - h:i a\", strtotime ($mt->st_time)));";
$stc = "echo nl2br (escape($mt->st_content));";
}
<<<TEXT2
<strong>Conversation:</strong><br><br>
$fn<br>
$time<br>
$stc<br><br>
Thanks,<br>
Support Team
);
TEXT2
?>