forked from PHPMailer/PHPMailer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retain uploaded extension in the attachment examples so that the MIME…
… type is more easily obtained
- Loading branch information
Showing
2 changed files
with
10 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,12 @@ if (array_key_exists('userfile', $_FILES)) { | |
$mail->addAddress('[email protected]', 'John Doe'); | ||
$mail->Subject = 'PHPMailer file sender'; | ||
$mail->Body = 'My message body'; | ||
//Attach multiple files one by one | ||
// Attach multiple files one by one | ||
for ($ct = 0, $ctMax = count($_FILES['userfile']['tmp_name']); $ct < $ctMax; $ct++) { | ||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])); | ||
// Extract an extension from the provided filename | ||
$ext = PHPMailer::mb_pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION); | ||
// Define a safe location to move the uploaded file to, preserving the extension | ||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])) . '.' . $ext; | ||
$filename = $_FILES['userfile']['name'][$ct]; | ||
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) { | ||
if (!$mail->addAttachment($uploadfile, $filename)) { | ||
|