Forum Moderators: coopster
<?php
require'../../../connect.php';
require 'PHPMailerAutoload.php';
$stmt = $dbc->prepare("SELECT Email, UserName FROM Members WHERE Type LIKE 'Client'");
$stmt->execute();
while($row = $stmt->fetch()) {
$Email = $row['Email'];
$UserName = $row['UserName'];
sendemail($Email, $UserName);
}
function sendemail($Email, $UserName){
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'exampleATgmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('exampleATgmail.comm', 'The Services App');
$mail->addAddress($Email); // Name is optional
$mail->addReplyTo('exampleATgmail.com', 'The Services App');
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'Hello ".$UserName."<br> This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
$mail->SMTPDebug = 2;
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent to ".$UserName."<br>';
}
}
?>
[edited by: not2easy at 2:31 am (utc) on Oct 17, 2018]
[edit reason] changed email to "exampleATgmail.com" [/edit]
<?php
require'../../../connect.php';
require 'PHPMailerAutoload.php';
$result = mysqli_query($dbc, "SELECT * FROM Members WHERE Type LIKE 'Client'");
while ($Members = $result->fetch_assoc()) {
$UserName = $Members['UserName'];
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'NotARealEmail@gmail.com'; // SMTP username
$mail->Password = 'NotARealPassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('NotARealEmail@gmail.com', 'The Services App');
$mail->addAddress($Members['Email'], 'Name of Person'); // Add a recipient
// $mail->addAddress('exampleEmail'); // Name is optional
$mail->addReplyTo('NotARealEmail@gmail.com', 'The Services App');
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'One of your notifications has marked themselves as available';
$mail->Body = 'Hello, <br> one of your notifications is available.';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
$mail->SMTPDebug = 2;
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
}
?>