For whatever reason, the string that I pass to chunk_split(base64_encode()) tosses the first part of the string, and only part comes through. The plaintext version reads fine if I leave out the base_64 encoded section. While I suppose that I can just leave things alone and it will work, I want to find out about this problem. The code that I'm writing is this, part of a larger class library:The part commented out is giving me trouble. The three lines above marked //} For instance, ifCode:public function adminEmail($subject,$body) { $eol = PHP_EOL; $plaintext = strip_tags($body); $boundary = uniqid(rand(), true); $headers = "From: <" . $this->fromemail . ">".$eol; $headers .= "Reply-To: <" . $this->replyto . ">".$eol; $headers .= "Cc: ".$this->admincc.$eol;; $headers .= "Content-Type: multipart/alternative; boundary=\"$boundary\"; type=\"multipart/alternative\""; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "--$boundary".$eol; $headers .= "Content-Type: text/plain; charset=ISO-8859-1".$eol; $message = chunk_split($plaintext); // $message .= "--$boundary".$eol; // $message .= "Content-Type: text/html; charset=ISO-8859-1\n" . "Content-Transfer-Encoding: base64".$eol; // $message .= chunk_split(base64_encode($body)); // chunk_split adds the ending "\r\n" $message .= "--$boundary--".$eol; return @mail($this->adminemail, $subject, $message, $headers); // true if email sent }Then the output in the encoded email part is "1.9073486328125E-6 seconds." while the plain text in the email is "20160509 11:15:40.7827080 123 interpolations generated in 1.9073486328125E-6Code:$time_execution = microtime(true) - $time_start; $done = "$pronum interpolations generated in $time_execution seconds."; $body = date('Ymd H:i:s'.substr(microtime(), 1, 8))." ".$done;
seconds." I can test the contents of the base64 encoding using an on-line tester to verify that they are entirely different, or missing the first part. I'm using PHP 5.4.45 (I'm told that this makes it essentially v 5.5) What gives with chunk_split(base64_encode())? And in another instance of a similar function, html lines are split leaving pieces that don't mean anything by themselves, ie the metadata lines. Am I overlooking something? This never happened before when used on a php 5.2 system and I haven't found any documentation changes between these versions.



Reply With Quote

Bookmarks