Attachment sending using email as filename with PHPMailer

0

I am using PHPMailer to send a form and I would like the attached files when they arrived in the destination email, had the file name the email of the person I sent, not the file name, I did several tests here but I could not.

<input type="file" name="arquivo[]" multiple>
$email = strip_tags(trim($_POST['email']));
$arquivo = $_FILES['arquivo'];

if ($arquivo['size'][0] != 0) {
    for ($i = 0; $i < count($arquivo ['tmp_name']); $i++) {
        $mail->AddAttachment($arquivo ['tmp_name'][$i], $arquivo['name'][$i]);
    }
}
    
asked by anonymous 26.05.2018 / 17:51

1 answer

0

The code $email[$i] will only take the first character of the string. In the case of for , when the variable $i is equal to 0 , it will get the first character ( 0 represents the index of the first character of a string). Example:

$str = "Olá";
$str[0] -> O
$str[1] -> l
$str[2] -> á

Only the variable $email is concatenated with the variable $i , since $email is not part of the array, it is a fixed value variable:

$mail->AddAttachment($arquivo ['tmp_name'][$i], $email.$i);
    
28.05.2018 / 03:29