First, sorry for my English :) I have some problem with phpmailer. I want to send emails to multiple people with dedicated attachment to them (pdf). Email address must by downloaded from MySQL. But I dont know how can I do it. PDF file have the same name like column 'name' in datebase table. For example I have:
- User name: XXX
- PDF name (from ftp): XXX.pdf
- email: somemail@example.com
this is one example, I have a lot of users with lots of pdfs.
Simplifying what I want: user XXX must receive email with XXX.pdf but user YYY must receive email with YYY.pdf.
I dont know if you understand what I mean :)
At this moment I have something like this and i dont know how to assign name to email (dynamically?) in query
$stmt = $dbh->prepare('SELECT id, name, email FROM users WHERE name ="SomeUserName" ');
// how to assign name to email??
$stmt->execute();
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->CharSet = 'UTF-8';
$body = 'SOME TEXT IN BODY';
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->SetFrom('name@yourdomain.com', 'name@yourdomain.com');
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
$mail->addAttachment("pdf/07.2017/".str_replace('.','_',$row['name']).".pdf");
$address = $row["email"];
}
$mail->AddAddress($address, "SOME TEXT");
$mail->Subject = "SOME SUBJECT";
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo 'send';
} else {
echo 'didnt send';
}