i'm trying to send an E-Mail with PHP's inbuild mail()
function but i didnt get how i send two attachments in this mail. I already can send Plaintext, Html Text and one attachment in my mail but it failes to send another.
I'm sure anything in my mailheader is wrong but i dont know what. Here is my PHP-Code which generates the Email:
$attachment = chunk_split(base64_encode(file_get_contents('/var/www/html/style/img/smalllogo.png')));
$attachment2 = chunk_split(base64_encode(file_get_contents('/var/www/html/style/img/header.png')));
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<?php echo $txtMailPlain;?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<?php echo $txtMailHtml;?>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: image/png; name="smalllogo.png"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
X-Attackment-Id: 1
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: image/png; name="smalsllogo.png"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
X-Attackment-Id: 2
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
I get the first attachment, called "smalllogo.png" but i didnt get the other one. And i'm not sure if i get the right plaintext message.
Thanks in advance, J. Doe ;)