I have a directory, having more than two files. i need to get all files for attaching to PHP mail function. So i need a php function to get all files from the directory. anybody could you please help me to give an idea to get a result.
thank you.
I have a directory, having more than two files. i need to get all files for attaching to PHP mail function. So i need a php function to get all files from the directory. anybody could you please help me to give an idea to get a result.
thank you.
Use glob() function, you will get all folders and files in current directory
foreach(glob('*') as $files){
echo "<br />".$files;
}
for more info, please visit http://php.net/manual/en/function.glob.php
for specific file extension e.g. .php
, you can use glob('*.php')
You can use a scandir() function to list the files. So you can loop to add the files
<?php
$directory = '/path/to/my/directory';
// Eliminate folder "." and ".."
$files = array_diff(scandir($directory), array('..', '.'));
?>
I recommend you to use PHPMailer for send emails.
<?php
$email = new PHPMailer();
$email->From = 'you@example.com';
$email->FromName = 'Your Name';
$email->Subject = 'Message Subject';
$email->Body = $bodytext;
$email->AddAddress( 'destinationaddress@example.com' );
foreach($files as $file):
$email->AddAttachment( $file );
endforeach;
return $email->Send();