Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从电子邮件正文中删除标题_Php_Email_Header_Content Type - Fatal编程技术网

Php 从电子邮件正文中删除标题

Php 从电子邮件正文中删除标题,php,email,header,content-type,Php,Email,Header,Content Type,我在使用电子邮件同步应用程序时遇到问题,我正在为我的项目开发一个对话模块,因此我从电子邮件帐户中提取了电子邮件正文和附件,但问题是我在电子邮件正文中也得到了一些标题文本,如 "--PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 Content-Type: text/plain --PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 " 我想把它去掉 实际产量为 --PHP-alt-9ce0b24f8

我在使用电子邮件同步应用程序时遇到问题,我正在为我的项目开发一个对话模块,因此我从电子邮件帐户中提取了电子邮件正文和附件,但问题是我在电子邮件正文中也得到了一些标题文本,如

"--PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 Content-Type: text/plain --PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 "
我想把它去掉

实际产量为

--PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 Content-Type: text/plain --PHP-alt-9ce0b24f8d52c4d37de61cb315107795d140f8b7 Content-Type: multipart/related; boundary="PHP-related-9ce0b24f8d52c4d37de61cb315107795d140f8b7" --PHP-related-9ce0b24f8d52c4d37de61cb315107795d140f8b7 Content-Type: text/html Dear Milind

Thank you for choosing XXXXX for your limo hire.

Please accept this e-mail as confirmation the following booking has been
confirmed and requires you to print, sign and return the attached
contract with us, either by e-mail, fax or post, within 3 days.
To view contract for booking please click here
We would like to draw your attention to our agreed Terms and
Conditions concerning the booking and ask that you ensure you comply,
which can be found on our website www.xxxxx.co.uk

If this has been received in error, please contact our Office
immediately on XXXXXXX or XXXXXX.

Regards
Company name
TEL:
我想要像这样的东西

Dear Milind

    Thank you for choosing XXXXX for your limo hire.

    Please accept this e-mail as confirmation the following booking has been
    confirmed and requires you to print, sign and return the attached
    contract with us, either by e-mail, fax or post, within 3 days.
    To view contract for booking please click here
    We would like to draw your attention to our agreed Terms and
    Conditions concerning the booking and ask that you ensure you comply,
    which can be found on our website www.xxxxx.co.uk

    If this has been received in error, please contact our Office
    immediately on XXXXXXX or XXXXXX.

    Regards
    Company name
    TEL:
我试过
substr()
,但没有那么大帮助 任何正则表达式都可以是? 这是发送电子邮件的代码 假设body string=
$email\u message
,其中所有电子邮件格式都以“string”格式写入 PS:请注意,有些电子邮件包含附件

$subject = 'A sample email - Dual Format plus attachment plus inline';

// Create a boundary string.  It needs to be unique (not in the text) so ...
// We are going to use the sha1 algorithm to generate a 40 character string:
$sep = sha1(date('r', time()));

// Define the headers we want passed.
$headers = "From: StarLimosine <sender@gmail.com> \r\n X-Mailer: Custom PHP Script";
//$headers.="\r\nCc:sender@gmail.com";
$headers.="\r\nBcc:sender@gmail.com , sender@gmail.in";
// Add in our primary content boundary, and mime type specification:
$headers .= 
    "\r\nContent-Type: text/html; boundary=\"PHP-mixed-{$sep}\"";

// Prepare our attachment file - Read it in, encode it and split it
//$attached = chunk_split(base64_encode(file_get_contents('attachment.zip')));

// Also now prepare our inline image - Also read, encode, split:
$inline = chunk_split(base64_encode(file_get_contents('images/Logo.png')));

// Now the body of the message.
$body =<<<EOBODY
--PHP-mixed-{$sep}
Content-Type: multipart/alternative; boundary="PHP-alt-{$sep}"

--PHP-alt-{$sep}
Content-Type: text/plain


--PHP-alt-{$sep}
Content-Type: multipart/related; boundary="PHP-related-{$sep}"

--PHP-related-{$sep}
Content-Type: text/html

$email_message
<strong>
Star Limousines<br/>
TEL: 0800 9 556 556 <br/>
or 01435 813494</strong><br/>
<span style="font-size:10px">Registerd Office Pick Hill Farm, Horam East Sussex TN21 0JR</span>

--PHP-mixed-{$sep}--
EOBODY;
$body=$email_message;

mail($to,$subject,$body);
$subject='A sample email-Dual Format plus attachment plus inline';
//创建一个边界字符串。它需要是唯一的(不是在文本中),所以。。。
//我们将使用sha1算法生成一个40个字符的字符串:
$sep=sha1(日期('r',时间());
//定义我们想要传递的标题。
$headers=“From:StarLimosine\r\n X-Mailer:Custom PHP脚本”;
//$headers.=“\r\nCc:sender@gmail.com";
$headers.=“\r\nBcc:sender@gmail.com , sender@gmail.in";
//添加我们的主要内容边界和mime类型规范:
$headers.=
“\r\n内容类型:text/html;boundary=\'PHP mixed-{$sep}\”;
//准备我们的附件文件-将其读入,编码并拆分
//$attached=chunk\u split(base64\u编码(文件获取内容('attachment.zip'));
//现在还要准备我们的内联图像-也可以读取、编码、拆分:
$inline=chunk\u split(base64\u编码(文件获取内容('images/Logo.png'));
//现在是消息的主体。

$body=在任何时候,标题都在前两行,对吗?如果是这样的话,你可以这样做:

substr($email, strpos($email, PHP_EOL, strpos($email, PHP_EOL) + 1));

仅当使用GET remove this发布数据时添加此项

$headers .= 
    "\r\nContent-Type: text/html; boundary=\"PHP-mixed-{$sep}\"";

您将得到没有标题的回复

问题在于您的电子邮件提取方法。请使用适当的MIME库,而不是事后尝试修复它。请您描述更多信息,或者给我URL或其他信息。您不应该自己生成MIME电子邮件。用更少的代码为您做到这一点。感谢所有人的帮助,PHPMailer为我工作!谢谢Praveen它很有用它解决了我的一些问题但不是全部