2

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 ;)

J. Doe
  • 837
  • 1
  • 7
  • 18

1 Answers1

0

you have written in both place

<?php echo $attachment; ?>

you have to write one of place is <?php echo $attachment2; ?>

Amit Gaud
  • 756
  • 6
  • 15
  • normally it should at the same attachment with another name actually. But i tried to change it and it didnt work too. – J. Doe May 15 '17 at 10:31