Warum wird hier keine neue Linie präsentiert?Php

PHP-Programmierer chatten hier
Anonymous
 Warum wird hier keine neue Linie präsentiert?

Post by Anonymous »

Ich habe das folgende Stück Code geschrieben, um einen im E-Mail-Stream bestehenden E-Mail-Stream zu lesen (oder .Eml-Datei während des Testens). PrettyPrint-Override ">

Code: Select all

function sendMailForward($email) {
// Load recipients from ENV (comma-separated list)
$newRecipients = preg_split("/,\s*/", $_ENV['ADMIN_EMAIL'] ?? '', -1, PREG_SPLIT_NO_EMPTY);

// For StackOverflow: This passes in a comma-separated list of emails, this line is not part of the problem.

$raw_email = "";
while (!feof($email)) {
$raw_email .= fread($email, 1024);
}
fclose($email);

// Extract headers for a clean subject and sender
$headers = [];
$lines = explode("\n", $raw_email); // This line, somehow, doesn't see newlines in the stream.
foreach ($lines as $line) {
echo "New line!\n"; // This was me trying to test and what should show up multiple times, only shows up once.
if (strpos($line, ":") !== false) {
$parts = explode(":", $line, 2);
$key = trim($parts[0]);
$value = trim($parts[1]);
$headers[$key] = $value;
}
// Stop at the first blank line, which marks the end of headers
if (trim($line) == "") {
break;
}
}

$original_subject = isset($headers['Subject']) ? "FWD: " . $headers['Subject'] : "FWD: No Subject";
$original_from = isset($headers['From']) ? $headers['From'] : "unknown sender";

$subject = $original_subject;
$message = "--- Original message from $original_from ---\n\n" . $raw_email;
$extra_headers = "From: [email protected]\r\n"; // Customize 'From' address

foreach ($newRecipients as $recipient) {
$to = $recipient;
// Send the email
mail($to, $subject, $message, $extra_headers);
}
}

< /code>
Was soll ich im obigen Code ändern? Sollte ich eine neue Linie erzwingen, um anzuhängen? Oder gibt es noch etwas, das mir bewusst sein sollte. Dies ist die E-Mail, die ich zum Testen verwenden kann.
From: "Megan at TCGplayer" 
To: "TCGPlayer Account" 
Subject: Test Email for Forwarding
Date: Sat, 28 Sep 2025 08:00:00 -0400
Message-ID: 
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

Hello,

This is a test email to verify the mail forwarding module.

Best regards,
Test System
< /code>
Bearbeiten 2: Jemand hat nach dem verwendeten Code gefragt.// Read original message from stdin
$rawEmail = file_get_contents('php://stdin');

sendMailForward($rawEmail);
Stellen Sie es einfach auf, es nur aufzurufen.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post