jeudi 13 août 2015

PHPMailer MySQLi multiple email addresses

I am at the end of my rope and would really really appreciate any help you could spare...

I have the following code and although it works on an individual basis, I can for the life of me not make it work so that all email addresses are sent at the same time using PHPMailer.

I have scoured StackOverflow for the past few months, trying an exhaustive amount of combinations without success. There are a number of discussions on this forum and although I have tried all the solutions on here, I can still not make it work. If I offend anyone by potentially duplicating the question, please accept my apologies in advance.

// Require the form_functions to process the form
    require('databaseConnect.php');

    // Require the Email Class Functions
    require("class.phpmailer.php");
    require("class.smtp.php");

    // User Not Purchased               
        $result = mysqli_query($databaseConnect, "SELECT fname, email FROM table WHERE condition = 'condition' LIMIT 50");

        /* fetch associative array */
        while($row = $result->fetch_array()){
            $rows[] = $row; 
        }

        foreach($rows as $row) {
            $userFname = $row["fname"];
            $userEmail = $row["email"];
        }

$mail = new PHPMailer();

$mail->IsSMTP(); // Telling the Class to use SMTP

$mail->SetFrom("No_Reply@girrawaagames.com", "Girrawaa Games"); // Valid email address from sender and Company name. Only Company name will be displayed

//$mail->AddAddress("$userEmail");

$addr = explode(',',$userEmail);

foreach($addr as $ad) {
$mail->AddAddress(trim($ad));
}

$mail->Subject='CASH Trader'; // This adds the subject title in the subkect line field

$mail->AddAttachment('attachement.doc'); // This adds the file to be attached to the email 

$mail->Body="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://ift.tt/kkyg93\">
<html xmlns=\"http://ift.tt/lH0Osb\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
<title>CASH Trader</title>
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />

</head>

<body yahoo bgcolor=\"#ccffff\" style=\"margin:0; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px;\">
        <tr>
            <td bgcolor=\"#ffffff\" style=\"padding-top:40px; padding-right:30px; padding-bottom:20px; padding-left:30px;\">
                <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
                    <tr>
                        <td align=\"center\" style=\"color:#153643; font-family:Arial, Helvetica, sans-serif; font-size:24px;\">
                        <b>Hi " . $userFname . "</b>
                        </td>
                    </tr>
                </table>
              </td>
         </tr>

</body>
</html>";

            if($mail->send()){
                $updateCampaign = "UPDATE table SET row = 'value' WHERE email = '$userEmail'";
                $result = mysqli_query($databaseConnect, $updateCampaign);
                }           

        mysqli_free_result($result);

    mysqli_close($con); 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire