您可以遍历文件夹中的所有图像并使用 foreach 循环添加它。例如:
<?php
function get_files ($dir, $_ext = 'jpg') {
$files = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file == '.' || $file == '..') continue;
$ext = pathinfo($file, PATHINFO_EXTENSION);
if ($ext == $_ext) {
$files[] = $file;
}
}
closedir($dh);
}
}
return $files;
}
/**
* You can change the second parameter so you can get other image types
* (png, gif, etc.)
*/
$images = get_files ("/path/to/folder/of/images/");
foreach ($images as $image) {
$mail->AddEmbeddedImage ($image, 'image');
}
?>
取自PHP.net的目录代码。