如何在电子邮件主题中添加票证 ID 后使邮件线程正常工作


How to make mail threading work after adding ticket id in the email subject

我正在研究PHP的票务系统。我将邮件转换为票证。当用户从票务系统回复邮件时,它会将邮件作为新邮件发送给客户。没有消息/邮件线程。

我认为,我的问题与主题末尾添加的票证 ID 有关。(例如 Subject: Installation Problem [#EMSY45]

我已经在标头中传递了消息 ID 和引用

我正在使用PHPMailer发送邮件。

这是我的代码:

$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = str_replace('/', '', $host); // Specify main and backup SMTP servers
if($outgoing_server_details['smtp_auth'] == 1)
        $mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $outgoing_server_details['server_username']; // SMTP username
$mail->Password = $outgoing_server_details['server_password']; // SMTP password
$mail->SMTPSecure = $protocol; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $port;
$mail->setFrom($outgoing_server_details['from_email_field'], $from_name);
$mail->addAddress($data['_from'], $to_name); // Add a recipient
$mail->addReplyTo($outgoing_server_details['from_email_field'], $reply_to_name);
$message_id = $data['message_id'];
$mail->AddCustomHeader('In-Reply-To', $message_id);
$mail->AddCustomHeader('References', $message_id);
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = $data['subject'];
$mail->Body    = $mail_content;
$mail->send();
如果您需要在

电子邮件的末尾添加票证 ID 主题,请尝试此操作。

$mail->Subject = "Installation Problem [".$message_id."]";

$mail->Subject = $data['subject'].$message_id;

还有一个更正

$mail->isHTML(true);//应该总是在设置正文之后出现。

即,

$mail->Subject = $data['subject'].$message_id;
$mail->Body    = $mail_content;
$mail->isHTML(true);
$mail->send();