Is it common for base64-encoded email attachments in PHP to contain spaces, and is this considered normal behavior?

Base64-encoded email attachments in PHP may contain spaces due to line breaks inserted during encoding. This is considered normal behavior as it helps prevent long lines from being truncated by email servers. To handle this, you can simply remove any spaces and line breaks from the base64-encoded attachment before sending the email.

$attachment = chunk_split(base64_encode($file_contents));
$attachment = str_replace(array("\r", "\n", " "), "", $attachment);