PHPMailler Attachment with Tmp name

0

I have the following code in PHP, using PHPMailer to email files from a multiple upload, is working the problem is that in the email the name of the files gets the name of the tmp folder for example: "/ tmp / php / Z9MDY7" instead of the name of the file that was attached, but in the folder of the server where these files go, the name is correct, what could it be?

Code:

$total = count($_FILES['pdfanexo']['name']);

for($i=0; $i<$total; $i++) {                                              
    $tmpFilePath = $_FILES['pdfanexo']['tmp_name'][$i];
    if ($tmpFilePath != ""){
        $newFilePath = "Marcas/" .$vregistro. $d. "/". $_FILES['pdfanexo']['name'][$i];
        if(move_uploaded_file($tmpFilePath, $newFilePath)) {            
            $mail->addAttachment($newFilePath, $tmpFilePath);       //Attachment Documentos Múltiplo Upload (PDF-DOCUMENT)  
        }
    }
}
    
asked by anonymous 28.09.2017 / 15:18

1 answer

1

The declaration of the addAttachment method is:

/**
 * Add an attachment from a path on the filesystem.
 * Returns false if the file could not be found or read.
 * @param string $path Path to the attachment.
 * @param string $name Overrides the attachment name.
 * @param string $encoding File encoding (see $Encoding).
 * @param string $type File extension (MIME) type.
 * @param string $disposition Disposition to use
 * @throws phpmailerException
 * @return bool
*/
public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')

And you're passing $tmpFilePath instead of filename in the second parameter. Please try the exchange below:

From:

$mail->addAttachment($newFilePath, $tmpFilePath);

To:

$mail->addAttachment($newFilePath, $_FILES['pdfanexo']['name'][$i]);
    
28.09.2017 / 15:34