i am working on sending batch emails, however when formatting the table i get the table headers and only one row of data from the table, i have tried using php to loop through and display all rows (total of 10) but i am not having any luck, Help appreciated.
<?php
$db = new PDO("mysql:dbname=website4.0;host=localhost", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = ("SELECT * FROM students, criteria_table, email, buildtable ");
$statement = $db->prepare($query);
$statement->execute();
while($row = $statement->fetch()) {
$id = $row['studentID'];
$name = $row['name'];
$email = $row['email'];
$studentID = $row['studentID'];
$title = $row['Title'];
$heading1 = $row['Heading1'];
$heading2 = $row['Heading2'];
$heading3 = $row['Heading3'];
$heading4 = $row['Heading4'];
$subject =$row['subject'];
$setfrom =$row['setfrom'];
$yourname=$row['your_name'];
$criteria=$row['Criteria'];
$description=$row['Description'];
$mark=$row['Mark'];
sendEmail($id, $email, $title, $heading1, $heading2, $heading3,
$heading4, $name, $studentID, $subject, $setfrom, $yourname,
$criteria, $description, $mark);
}
This is the function i am calling to try and build the table:
function sendEmail($id, $email, $title, $heading1, $heading2,
$heading3, $heading4, $name, $studentID, $subject, $setfrom,
$yourname, $criteria, $description, $mark){
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
$db = new PDO("mysql:dbname=website4.0;host=localhost", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = ("SELECT * FROM buildtable, criteria_table");
$statement = $db->prepare($query);
$statement->execute();
$values = $statement->fetchAll();
foreach($values as $row){
$tit = $row['Title'];
$heading1 = $row['Heading1'];
$heading2 = $row['Heading2'];
$heading3 = $row['Heading3'];
$heading4 = $row['Heading4'];
}
foreach($values as $row){
$htmlversion=
"<h1>".$tit."</h1>Name: ".$name."<br>ID: ".$id."<br><table><tr>
<th>".$heading1."</th><th>".$heading2."</th><th>".$heading3."</th>
<th>".$heading4."</th></tr> <tr><td>".$row['Criteria']."</td>
<td>".$row['Description']."</td><td>".$row['Mark']."</td></tr>";
}
$textVersion="Hi ".$name.",.\r\n This is your StudentID:
".$studentID."text Version";
$mail->isSMTP(); // Set
mailer to use SMTP
$mail->Host = ' smtp.mailtrap.io'; //
Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP
authentication
$mail->Username = 'b74afc48436e94'; // SMTP
username
$mail->Password = '90b37082eab90a'; // SMTP
password
$mail->Port = 25; // TCP port to
connect to
$mail->setFrom($setfrom, $yourname);
$mail->addAddress($email); // Name is optional
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add
$mail->isHTML(true); // Set email
format to HTML
$mail->Subject = $subject;
$mail->Body = $htmlversion;
$mail->AltBody = $textVersion;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent to Username : '.$name.' Email:
'.$email.'<br><br>';
}
}
?>
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2G1k6a7
via IFTTT
Aucun commentaire:
Enregistrer un commentaire