email support template

I’m working on our support system right. Basically, its a watered (very much so) version of osticket. If anyone has used it before, it has this default answer thing and i’m trying to recreate it for ours. I hadn’t thought of doing it with customer info in the response, but i was asked if i could it. The information is already there, but i’ve never done this kind of thing and am not sure how to make it.

I have a seperate page where the templates are created, so if i could have it so if some variable were given (like %cname for the customer name, $sname for the staff name, etc), the script could put the proper info in there upon submission.

As an example, if i were to create a template like
Hi %cname. To get started with our service, simply provide me with your Label Name (Artist Name if unsigned), PayPal E-mail, and Country (Where are you from?). From there, I’ll be able to create your account. Please let us know if you have any other questions - %sname

I think i know what to do here, probably need to use something like str_replace() or preg_replace() to find the necessary variables and replace them with the needed information. that’s kinda how bbcode is done right?

ok, i’m confused as to why this doesn’t work. i’ve looked at example after example and its basically the same as those, but yet it doesn’t want to work.
[php]
//for default answer
$uname = $_POST[‘u_name’];
$aname = $_POST[‘a_name’];

//replace template variables
$find = array("%name%", “%admin%”);
$repl = array($uname, $aname);

$ansr = str_replace($find, $repl, $_POST[‘n_answer’]);

print_r( $ansr);
[/php]

Do i need to use preg_replace instead?

Well, after studying the function at http://php.net/manual/en/function.str-replace.php
It appears that there are lots of issues with different errors doing it that way. If someone types in
“name” as the name it will cause problems. They say to use preg_replace.

It works like the str_replace, but, is more of what you really want. Here is the links for it. Note sample #2 down a little on the page. I think that will work for you…
http://www.php.net/manual/en/function.preg-replace.php

Good luck…

I’ll give it a try and let you know, thanks :slight_smile:

I figured out the problem. str_replace does work, the problem is that the information that i’m trying to replace the variables with wasn’t getting there. I made a very stupid mistake. The hidden fields i was using to store the replacement info was in the wrong form. I didn’t discover it until i did a print_r on $_POST.

Its working now, thanks for your time :slight_smile:

Great! Always nice to finish a problem. Glad you found it!

I just feel really stupid right about now. such a simple problem turned into an all day project. should’ve been the first thing i looked at but instead i went way ahead of myself.

LOL, no problem! Been there, done that! Always a warm fuzzy feeling finding the problem…

CYA in the bitstream…

well, one problem solved, another one cropped up. Its removing the line breaks. If i use a selected response, it shows up properly in the text area, but when i hit answer and get the email, its one large run on paragraph.

this is what i get

test has been replied to by richei.

Hi richard,
Please provide me with the following: Label Name (Artist Name if Unsigned), PayPal E-mail, and Country.
From there we’ll go ahead and create your account so you can begin uploading your music to iTunes.
Please let us know if you have any questions - Richard Rowlands

Please use this link to reply.

but its supposed to be

test has been replied to by richei.

Hi richard,

Please provide me with the following: Label Name (Artist Name if Unsigned), PayPal E-mail, and Country.

From there we’ll go ahead and create your account so you can begin uploading your music to iTunes.

Please let us know if you have any questions - Richard Rowlands

Please use this link to reply.


That’s how it is in the database. I’m not sure if its because of the replacement process or what, it i need to get it fixed asap.

The strange thing is that if i type a message, everything works fine. Code is below
[php]<?php
require_once ‘config.php’;
require_once ‘functions.php’;

$id = $_GET[‘id’];
$qry = mysql_query(“SELECT * FROM venzo_contactus WHERE id = ‘$id’”);
$end = 0;

if(isset($_GET[‘end’])) {
$end = 4;
}

if(mysql_num_rows($qry) == 0) {
echo “There was no record found with the id of $id”;
} else {
$r = mysql_fetch_assoc($qry);

if(empty($r['last_answered_by'])) {
	$ans = "";
} else {
	$val = explode(', ', $r['last_answered_by']);
	$ans = end($val);
}

}

if(isset($_POST[‘close’])) {
$id = $_POST[‘id’];
$req_id = $_POST[‘req_id’];

$up = mysql_query("UPDATE venzo_contactus SET status = 0 WHERE id = $id AND req_id = '$req_id'") or exit(mysql_error());

if($up) {
	$suc = "This message has been successfully closed.";
	$end = 1;
}

}

if(isset($_POST[‘Answer’])) {
$id = $_POST[‘id’];
$req_id = $_POST[‘req_id’];

$find = mysql_query("SELECT * FROM venzo_contactus WHERE id = '$id'");
$f = mysql_fetch_assoc($find);

if(!empty($r['last_answered_by'])){ 
	if(strstr($r['last_answered_by'],$_SESSION['adminname'])){ 
		$temp = explode(', ',$r['last_answered_by']); 
		$temp = array_filter($temp,filterArray); 
		$str = implode(', ', $temp); 
		$str .= ', '.$_SESSION['adminname']; 
	} else { 
		$str = $f['last_answered_by'].", ".$_SESSION['adminname'];
	}
} else {
	$str = $_SESSION['adminname']; //Just have it one its own 
}

$status = 3;

//for default answer
$uname = $_POST['u_name'];
$aname = $_POST['a_name'];

//replace template variables
$find = array('%name%', '%admin%');
$repl = array($uname, $aname);

$ansr = str_replace($find, $repl, $_POST['n_answer']);

if(empty($r['answer'])) {
	$ansrs = add_slashes_recursive($ansr);
	$up = mysql_query("UPDATE venzo_contactus SET last_answered_by = '$str', answer = '$ansrs', status = $status WHERE id = $id AND req_id = '$req_id'") or exit(mysql_error());
} else {
	$ansrs = '\r\n'.add_slashes_recursive($ansr);
	$up = mysql_query("UPDATE venzo_contactus SET last_answered_by = '$str', answer = CONCAT(`answer`, '{$ansrs}'), status = $status WHERE id = $id AND req_id = '$req_id'") or exit(mysql_error());
}

if($up) {
	$suc = $f['subject']." has been successfully updated.<br />An email has been dispatched to ".$f['name'].", notifying the user that their question has been answered.";
	$end = 1;
	
	$headers = 'From: [email protected]' . "\r\n";
	$headers .= 'X-Mailer: PHP/' . phpversion();
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
	
	//$t = explode("\n", $_POST['n_answer']);
	/*if(in_array($find, $t)) {
		$replace = array($uname, $aname);
		$ansr = str_replace($find, $replace, $t);
		$ansr = add_slashes_recursive($ansr);
	}
	$put = end($t);*/
	
	//Venzo Support [ID] [Topic]
	$sub = "Venzo Support Request ID: ".$f['req_id']."";
	$message = "
	<html>
	<body>
	$f[subject] has been replied to by $_COOKIE[adminuser].<br />
	<br />".
	//strip_slashes_recursive($put)
	nl2br(stripslashes($ansr))
	."<br /><br />
	Please use this <a href='http://vmg.venzodigital.com/public_check_inquiries.php?req_id=$req_id'>link</a> to reply.
	</body>
	</html>";
	
	mail($f['email'], $sub, $message, $headers);
}

}
?>

Untitled Document
Name: <?=$r['name']?> Email: <?=$r['email']?> Phone: <?=$r['phone']?>
Submitted on: <?=$r['createdon']?> Updated on: <?=$r['date']?> Updated by: <?=$ans?>
<?=nl2br(strip_slashes_recursive($r['message']))?>
Answered by: <?=$r['last_answered_by']?>

<?php if($end == 1) { ?>
<?= $suc; ?>
<?php } else { ?>
<div style="float: right; width: 100px;">
	<select name="danswer" id="danswer" >
	<?php
	$ans = mysql_query("SELECT * FROM venzo_contactus_answers") or die(mysql_error());
	while($row = mysql_fetch_array($ans)) {
		echo "<option value='$row[id]'>$row[name]</option>";
	}
	unset($row);
	?>
	</select>
</div>
<div style="float: right; width: 100px;">
	<input type="button" id="a_select" name="select" value="Select" onclick="ajaxFunction();"/>
</div>
<input type="hidden" name="id" value="<?=$id?>" />
<input type="hidden" name="req_id" value="<?=$r['req_id']?>" />
<?=nl2br(strip_slashes_recursive($r['answer']))?>
<?php } ?> [/php]

It may be the use of
which is not what you normally use in a text area.
Usually, it is “\r\n” which means RETURN-NEWLINE. I have used many various ways to solve this program.
Most of the time, it depends on a lot of things. I had trouble with it because sometimes fields store the return one way and others store it in a second way. Try using “\r\n” instead of of “
” or “
” and see if that helps. Here is a link that explains it a bit. Just scroll down a little and read the samples…

http://php.net/manual/en/function.nl2br.php

Hope that helps… (Oh, can’t use stripslashes for /r/n must use the br2nl and nl2br, etc…)

Well that problem is fixed. Actually had to remove nl2br(), it was causing it to show the
in the text area. Also added /n to the replacement line, so that its replaced with html breaks.

Great! I thought it was something like that!

Sponsor our Newsletter | Privacy Policy | Terms of Service