简体   繁体   English

Gmail IMAP php邮件作为电子邮件的回复发送

[英]Gmail IMAP php mail send as reply of email

I want to send an email as reply in gmail through my Laravel CRM system. 我想通过我的Laravel CRM系统在gmail中发送电子邮件作为回复。

My code is as below: 我的代码如下:

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.Auth::user()->f_name.' '.Auth::user()->l_name.'<'.$gmail_address.'>'." \r\n" .
                        'Reply-To:  <'.$gmail_address.'>'. "\r\n" .
                        'Subject: '.$subject."\r\n".
                       'To: '.$to."\r\n".
                        'In-Reply-To:  <56F15324.7050704@xxxx.xxx>'. "\r\n" .
                        'References: <56F15324.7050704@xxxx.xxx>'. "\r\n" .
                        'X-Mailer: PHP/' . phpversion();

imap_mail ( $to , $subject ,$body,$headers);

But it sends it as a new email, ie not as a reply. 但它将其作为新电子邮件发送,即不作为回复。

Ideally it should add "Re: " to subject and append the actual email at the end of reply email body. 理想情况下,它应该添加“Re:”到主题并在回复电子邮件正文的末尾附加实际的电子邮件。

Any Help please.. 任何帮助请..

Your In-Reply-To and References headers are hardcoded to some magic value; 您的In-Reply-ToReferences标题被硬编码为一些神奇的值; that's probably not what you want to do. 这可能不是你想要做的。

Here is how I would improve the code: 以下是我将如何改进代码:

  • Use a library which handles the rather low level bits of RFC2047, RFC2231 and especially RFC 5322 for you. 使用一个库来处理RFC2047,RFC2231甚至RFC 5322的相当低级别的位。 It's very likely that any non-ascii characters in your user's l_name produce a non-compliant message. 用户的l_name中的任何非ascii字符很可能会产生不符合要求的消息。 Read the whole RFC5322 to understand how e-mails work. 阅读整个RFC5322以了解电子邮件的工作原理。 Read about various encodings which come into play. 阅读有关各种编码的信息。
  • Track the Message-Id of the message(s) that you're replying to, and set your own In-Reply-To & References headers accordingly. 跟踪您要回复的邮件的Message-Id ,并相应地设置您自己的In-Reply-ToReferences标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM