简体   繁体   English

管道电子邮件-如何发送正文,multipart / alternative / php preg_match_all返回1或空数组

[英]Pipe emails - how to send body, multipart/alternative / php preg_match_all returns 1 or empty array

Searching for the answer I found this script here 搜索答案,我在这里找到了这个脚本

However: 然而:

It can send body of received email as plain text only. 它只能将收到的电子邮件正文作为纯文本发送。 In order not to lose data (links) I need to send body in same format as it was received. 为了不丢失数据(链接),我需要以与接收时相同的格式发送正文。

Is there a simple change for this script to achieve that? 此脚本是否有一个简单的更改即可实现?

btw, Later, I need to save linked files (from email) on my server, and replace links in the body with my own. 顺便说一句,稍后,我需要将链接文件(来自电子邮件)保存在服务器上,并用自己的链接替换正文中的链接。

Thanks. 谢谢。

UPDATE 更新

Somehow i solved the first issue (adding original boundery value in my email), now, i have 3 more to go. 不知何故,我解决了第一个问题(在电子邮件中添加了原始的边界值),现在,我还有3个要解决的问题。 This code returns 1 with print_r($urls) 这段代码返回1并带有print_r($urls)

$pattern = '#^http://domain.com/(.*)(\w*)0\b#';
preg_match_all($pattern, $email, $urls);

same code returns empty array with those two outputs: 相同的代码返回带有两个输出的空数组:

1 print_r($urls, true) 1个print_r($urls, true)

2 print_r($urls[0], true) 2 print_r($urls[0], true)

like this: 像这样:

1 1个

Array
(
    [0] => Array
        (
        )

    [1] => Array
        (
        )

    [2] => Array
        (
        )

)

2 2

Array
(
)

However, when I test code here , it works like charm 但是,当我在这里测试代码时,它就像魅力

How can I get my values? 我如何获得自己的价值观? It will be very nice to have them in a variables, like $url1, $url2... 将它们包含在$ url1,$ url2等变量中会非常好。

Can anybody help? 有人可以帮忙吗? (Your time and effort is highly appreciated!) (非常感谢您的时间和精力!)

I will answer on my question. 我会回答我的问题。

Ok, I already solved this. 好的,我已经解决了这个问题。 Here is some info if somebody need it... 如果有人需要这是一些信息...

Regex had an extra ^ . 正则表达式有一个额外的^ Further on I improved pattern like this: "#http://domain.com/([=a-zA-Z\\d/-]+)(.|\\n|\\r)([a-zA-Z\\d/-]+)#" This urls have = and that was removed with this line: $var1=preg_replace("#=(.|\\n|\\r)#","",$var); 进一步,我改进了这样的模式: "#http://domain.com/([=a-zA-Z\\d/-]+)(.|\\n|\\r)([a-zA-Z\\d/-]+)#"这些URL带有= ,并且已在以下行中删除: $var1=preg_replace("#=(.|\\n|\\r)#","",$var); This is not the best way to go, but it worked. 这不是最好的方法,但是它有效。 I got my links in array, and later I was able to download files with file_get_contents() and file_put_contents() changing links was easy with str_replace . 我将链接放置在数组中,后来我可以使用file_get_contents()file_put_contents()下载文件,而使用str_replace更改链接很容易。 Everything is done with for loop because number of links in each email was not the same. 一切都通过for循环完成,因为每封电子邮件中的链接数量都不相同。

Happy Holidays everybody! 大家节日快乐!

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

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