Я пишу сценарий PHP, чтобы передать по электронной почте письмо в сценарий и сохранить его в базе данных.электронная почта .. Какой метод я могу использовать, чтобы получить только сообщение либо текстовую версию, либо HTML-версию. Это пример электронной почты, которую я получаю в настоящее время
Content preview: Mine Mine [...]
Content analysis details: (-0.1 points, 5.0 required)
pts rule name description
---- ---------------------- --------------------------------------------------
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
(techservice4real[at]gmail.com)
0.0 HTML_MESSAGE BODY: HTML included in message
-0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's
domain
0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid
-0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
-0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2)
[209.85.222.182 listed in wl.mailspike.net]
X-Spam-Flag: NO
--000000000000c1a52105822cd389
Content-Type: text/plain; charset='UTF-8'
Mine
--000000000000c1a52105822cd389
Content-Type: text/html; charset='UTF-8'
<div dir='ltr'>Mine<br></div>
--000000000000c1a52105822cd389--
В настоящее время это код, который я использую для получения электронного письма
#!/usr/local/bin/php -q
<?php
require_once('inc/init.php');
//chdir(dirname(__FILE__));
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// if(strlen($email)<1) {
// die();
// }
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$to="";
$subject = "";
$headers = "";
$message = "";
$bodyContent = "";
$myBody = "";
$splittingheaders = true;
for ($i=0; $i < count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i]."\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
$to = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
$data = explode("\n", $message);
mail("boomztechs@gmail.com", "You Have One new Email Piped", "A New Mail Message just Piped to you) ".$message);
Ваш ответ очень важен, спасибо ..