Customer emails automatically turn into a ticket
Moderator: mkoch227
-
- Posts: 2
- Joined: Thu Nov 09, 2006 2:34 am
Customer emails automatically turn into a ticket
I would love to see an add-on that would allow all emails to a specific address to automatically be turned into a ticket. Is this possible?
By the way, I LOVE, LOVE, LOVE this script. Awesome!
By the way, I LOVE, LOVE, LOVE this script. Awesome!
That's called e-mail piping, will be added someday but most likely not yet in the next version as I have a lot of things to consider first before making this work (handling SPAM, integrating piping, handling HTML e-mails, ...).
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
I have done this
1. Create a file in the support directory called process_email.php (note needs pecl package 'mailparse'). This script emulates the entry of the email:
2. If you want to process attachments then modify inc/attachements.php.inc as follows:
Change:
to:
3. Set up you email filter to pipe the email content to this script making sure the output goes to null. e.g. Use the following script:
I would recommend that you copy the email to another mailbox in case the script looses it. It does not have any error handling if something goes wrong.
This still needs a bit of refinement.
Code: Select all
<?php
$filename = "php://stdin";
$_SERVER['REMOTE_ADDR'] = 'Via Email';
/* if we were called to display a part, do so now */
function getContent($message)
{
$mime = $mime = mailparse_msg_create ();
mailparse_msg_parse($mime, $message);
$struct = mailparse_msg_get_structure($mime);
$parts = array();
foreach($struct as $st)
{
$section = mailparse_msg_get_part($mime, $st);
$info = mailparse_msg_get_part_data($section);
ob_start();
mailparse_msg_extract_part($section, $message);
$content = ob_get_contents();
ob_end_clean();
if (ini_get('magic_quotes_gpc'))
$info['content'] = mysql_escape_string($content);
else
$info['content'] = $content;
$parts[$st] = $info;
}
return $parts;
}
$message = getContent(file_get_contents($filename));
$_POST['subject'] = $message[1]['headers']['subject'];
$addresses = mailparse_rfc822_parse_addresses($message[1]['headers']['from']);
extract($addresses[0]);
$name = $display == '' ? "UnKnown" : $display;
$email = $address;
$_POST['name'] = $name;
$_POST['email'] = $email;
$_POST['category'] = 1;
$_POST['priority'] = 2;
$custom1 = $custom2 = $custom3 = $custom4 = $custom5 = '';
define('MAILUPLOAD',1);
$_FILES = array();
$_FILES['attachment']['tmp_name'] = array();
$_FILES['attachment']['name'] = array();
$_FILES['attachment']['size'] = array();
$i = 1;
foreach ($message as $index => $part)
{
if (preg_match('#^multipart/alternative#', $part['content-type']))
$mIndex = $index;
if (isset($mIndex) && preg_match('/^' . $mIndex . '/', $index))
{
if (preg_match('#text/plain#',$part['content-type']))
$body = $part['content'];
}
else
unset($mIndex);
if (!isset($body) && preg_match('#text/plain#',$part['content-type']))
$body = $part['content'];
if (!isset($body) && preg_match('#text/html#',$part['content-type']))
$body = $part['content'];
if (isset($part['content-name']))
{
$tempFile = tempnam('/tmp','mime_');
file_put_contents($tempFile, $part['content']);
$_FILES['attachment']['tmp_name'][$i] = $tempFile;
$_FILES['attachment']['name'][$i] = $part['content-name'] ;
$_FILES['attachment']['size'][$i] = strlen($part['content']);
$i++;
}
}
$_POST['message'] = $body;
include("submit_ticket.php");
?>
Change:
Code: Select all
if (!move_uploaded_file($_FILES['attachment']['tmp_name'][$i], $hesk_settings['server_path'].'/attachments/'.$file_name)) {
hesk_error($hesklang['cannot_move_tmp']);
}
Code: Select all
if (defined('MAILUPLOAD')) {
if (!rename($_FILES['attachment']['tmp_name'][$i], $hesk_settings['server_path'].'/attachments/'.$file_name)) {
hesk_error($hesklang['cannot_move_tmp']);
}
} else {
if (!move_uploaded_file($_FILES['attachment']['tmp_name'][$i], $hesk_settings['server_path'].'/attachments/'.$file_name)) {
hesk_error($hesklang['cannot_move_tmp']);
}
}
Code: Select all
#!/bin/bash
cd wwwdir/support
/usr/local/bin/php wwwdir/support/process_email.php > /dev/null
This still needs a bit of refinement.
Hi,
I created the script process_email.php in the support directory, and installed the mailparse package.
I piped the mail to the script using
When sending an email to the mail address, I get "Mail delivery failed", together with:
My exim log is telling me:
Any suggestions on what I'm doing wrong?
Thanks in advance!
I created the script process_email.php in the support directory, and installed the mailparse package.
I piped the mail to the script using
Code: Select all
"|/usr/local/bin/php /home/.../process_email.php > /dev/null"
Code: Select all
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
pipe to |/usr/local/bin/php /home/.../process_email.php > /dev/null
generated by test@domain.com
local delivery failed
pipe to |/usr/local/bin/php /home/.../process_email.php > /dev/null
generated by test@domain.com
local delivery failed
The following text was generated during the delivery attempts:
------ pipe to |/usr/local/bin/php /home/.../process_email.php > /dev/null
generated by test@domain.com ------
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>HelpDesk</title>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
<link href="hesk_style.css" type="text/css" rel="stylesheet">
<script language="Javascript" type="text/javascript" src="hesk_javascript.js"><!--
// -->
</script>
</head>
<body marginwidth="0" leftmargin="0">
PHP Warning: main(header.txt): failed to open stream: No such file or directory in /home/.../inc/header.inc.php on line 45
PHP Warning: main(): Failed opening 'header.txt' for inclusion (include_path='.:/usr/local/lib/php') in /home/.../inc/header.inc.php on line 45
<div align="center">
<center>
<table border="0" cellspacing="0" cellpadding="5" width="700" class="enclosing">
<tr>
<td>
PHP Warning: hesk_error(inc/header.inc.php): failed to open stream: No such file or directory in /home/.../inc/common.inc.php on line 356
PHP Fatal error: hesk_error(): Failed opening required 'inc/header.inc.php' (include_path='.:/usr/local/lib/php') in /home/.../inc/common.inc.php on line 356
Code: Select all
Child process of virtual_address_pipe transport returned 255 (could mean shell command ended by signal 127 (Unknown signal 127)) from command: /usr/local/bin/php
Thanks in advance!
Thanks for sharing pwillia6.
Just a heads-up if you are getting errors like "undefined function", this mod requires the Mailparse extension, see http://php.net/mailparse
Just a heads-up if you are getting errors like "undefined function", this mod requires the Mailparse extension, see http://php.net/mailparse
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Thanks for the quick reply!pwillia6 wrote:Your current directory needs to be the support directory. See the bash script above.
Also in the code above replace the line with the mysql_escape with:
$info['content'] = str_replace("'","\\'",$content);
The mysql escapes to much.
Maybe a stupid question, but what exactly shoul I do with the bash script?... Should I pipe the mail to that script instead of to the process_email.php, so that the pipe rule would be:
Code: Select all
"|/home/.../bashscript"
---
edit:
Yes, that way it works! The only problem now is that for each message received, 2 seperate tickets are created... Any suggestions?
---
another edit:
Fixed that too, by commenting out virtual_aliases_nostar in exim.conf
-
- Posts: 11
- Joined: Sat Dec 01, 2007 7:18 pm
Do I Need To Specify A E-Mail Address?
Do I Need To Specify A E-Mail Address? And If So How?
-
- Posts: 3
- Joined: Wed Mar 26, 2008 4:40 pm
Unless your host has it installed or can install it then no.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools