Jump to content


New Members
  • Posts

  • Joined

  • Last visited

coatse's Achievements


Newbie (1/5)



  1. Hi Kicken, I hope your well. Thanks for you reply. I have re writen the code with clearAddresses() command I am no longer getting any errors but all I get is blank screen. <?php error_reporting(E_ALL); ini_set('display_errors', 1); /** * This example shows how to send a message to a whole list of recipients efficiently. */ //Import the PHPMailer class into the global namespace use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\SMTP; error_reporting(E_STRICT | E_ALL); date_default_timezone_set('Etc/UTC'); require 'scripts/vendor/autoload.php'; //Passing `true` enables PHPMailer exceptions $mail = new PHPMailer(true); $mail->SMTPDebug = 3; $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->SMTPAuth = true; $mail->SMTPKeepAlive = true; //SMTP connection will not close after each email sent, reduces SMTP overhead $mail->Port = 587; $mail->Username = 'james@jhe.co.uk'; $mail->Password = '*****'; $mail->setFrom('reports@jhe.co.uk', 'JHE Reports'); $mail->Subject = 'Expiring Subscription for Customer'; //Connect to the database and select the recipients from your mailing list that have not yet been sent to //You'll need to alter this to match your database $mysql = mysqli_connect('localhost', 'root', '****'); mysqli_select_db($mysql, 'license_manager'); $result = mysqli_query($mysql, 'SELECT * FROM customersubscriptions WHERE SubRenew = 30'); foreach ($result as $row) { $mail->addAddress('james@jhe.co.uk', 'James Coates'); $mail->Body("This subscription is expiring on" . $row['subRenew']); $mail->send(); if (!$mail->Send()) { echo 'Something went wrong'; } else { echo 'Complete.'; } //Clear all addresses and attachments for the next iteration $mail->clearAddresses(); $mail->clearAttachments(); } Any Ideas? Many Thanks Coatse
  2. Hi All, I hope you are all well. I have been building a license manager for my business using PHP and MySQL. Its all going well but I've hit a snag. I know how to send an email and tested it using PHP Mailer. But What I am struggling in doing is fetching the data from the table and putting it into the the body of the email. Please see my code below. This may not be the best way to do this but I'm still learning <?php // Import PHPMailer classes into the global namespace // These must be at the top of your script, not inside a function use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; //Load Composer's autoloader require 'scripts/vendor/autoload.php'; require 'database.php'; $results=mysqli_query($conn,"SELECT * FROM customersubscriptions WHERE SubRenew =30"); ?> <?php if (mysqli_num_rows($result) > 0) { ?> <?php $i=0; while($row = mysqli_fetch_array($result)) { ?> <?php $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = 2; $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'TLS'; $mail->SMTPAuth = true; $mail->Username = 'james@jhe.co.uk'; // SMTP username $mail->Password = 'Coatez1989#'; // SMTP password (NB Dummy password) //Recipients $mail->setFrom('reports@jhe.co.uk', 'JHE Reports'); $mail->addAddress('james@jhe.co.uk', 'James Coates'); // Add a recipient //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Contact Us Message'; $mail->Body = "The new password is " . $row['SubRenew'] . "."; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); header('Location: tempage.php'); } catch (Exception $e) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; } } ?> Many Thanks
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.