简体   繁体   中英

PHPMailer send multiple attachments

HI im trying to send multiple attachment with php mailer but only one attachment being sent even both files are uploaded and path are correct below is code. in second iteration $mail->addAttachment return false.

if  (is_array( $email_attachment )) {

    foreach ($email_attachment as $attachment ) {

        $mail->addAttachment($attachment ); 

        var_dump($attachment);
        echo '<br/>';  

        var_dump($mail->addAttachment($attachment));
        echo '<br/>'; 
    }

     die();
}

dump result.

string(62) "D:\htdocs\express-english/wp-content/uploads/2016/10/23882.jpg" 
bool(true) 
string(63) " D:\htdocs\express-english/wp-content/uploads/2016/10/97778.jpg" 
bool(false)

Your 2nd string contains a space in front of it

string(63) " D:\htdocs\express-english/wp-content/uploads/2016/10/97778.jpg" 

you should trim that with

$attachment = trim($attachment);

before using $mail->addAttachment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM