Why when I use Wordpress wp_mail() to send an email with an attachment, are the pdfs sometimes corrupted?

Viewed 24

The following code works more than half the time, but sometimes the attachments are corrupted. I don't understand why. $attachments is an array of file paths.

            $this->post_content = apply_filters('the_content', $this->post_content);

            $separator = md5(time());
            $eol = PHP_EOL;
            $headers[] = "MIME-Version: 1.0".$eol;
            $headers[] = "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol;
            $headers[] = "Content-Transfer-Encoding: 7bit". $eol;

            error_log(print_r($attachments, true));

            $success = wp_mail($recipients, $this->post_title, $this->post_content, $headers, $attachments);
0 Answers
Related