<?php
try
{
$filepath = './dateiname.csv';
$mailfrom = 'webmaster@example.com';
$mailreceiver = 'root@world.org';
$mailsubject = 'Nur so';
$mailmessage = 'Hallo du!';
if(is_readable($filepath))
{
$mode = 'r';
$handle = fopen($filepath, $mode);
if(is_resource($handle))
{
$mailheader =
'From: ' . $mailfrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$mailbcc = array();
while (!feof($handle))
{
$row = fgetcsv($handle);
/*
$row[0] beinhaltet den Vornamen
$row[1] beinhaltet den Nachnamen
$row[2] die E-Mail-Adresse
*/
// Vorname Name <E-Mail-Adresse>
$mailbbc[] = $row[0] . ' ' $row[1] . ' <' . $row[2] . '>';
}
fclose($handle);
if(count($mailbcc) > 0)
{
$mailheader .= "\r\n" . 'Bcc: ' . implode(', ', $mailbcc);
if(!mail($mailreceiver, $mailsubject, $mailmessage, $mailheader))
{
throw new Exception('Can\'t send mail.');
}
}
else
{
throw new Exception('Can\'t find a receiver.');
}
}
else
{
throw new Exception(sprintf('Cannot open file "%s" with mode "%s".', $filepath, $mode));
}
}
else
{
throw new Exception(sprintf('The file "%s" doesn\'t exist or isn\'t readable.', $filepath));
}
}
catch(Exception $e)
{
echo (string) $e;
}