Artefacto made me look at the result with great attention, and I found a fix:
function myMail ($ to, $ subject, $ mail_msg, $ filename, $ contentType, $ pathToFilename) {
$ random_hash = md5 (date ('r', time ()));
$ headers = "From: webmaster@mysite.com \ r \ nReply-To:". $ to;
$ headers. = "\ r \ nContent-Type: multipart / mixed; boundary = \" PHP-mixed - ". $ random_hash." \ "";
$ attachment = chunk_split (base64_encode (file_get_contents ($ pathToFilename)));
ob_start ();
echo "
--PHP-mixed- $ random_hash
Content-Type: multipart / alternative; boundary = \ "PHP-alt- $ random_hash \"
--PHP-alt- $ random_hash
Content-Type: text / plain; charset = \ "utf-8 \"
Content-Transfer-Encoding: 7bit
$ mail_msg
--PHP-alt- $ random_hash--
--PHP-mixed- $ random_hash
Content-Type: $ contentType; name = \ "$ filename \"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$ attachment
--PHP-mixed- $ random_hash--
";
$ message = ob_get_clean ();
$ fh = fopen ('log.txt', 'w');
fwrite ($ fh, $ message);
$ mail_sent = @mail ($ to, $ subject, $ message, $ headers);
return $ mail_sent? "Mail sent": "Mail failed";
}
Valentin brasso
source share