For some strange reason my PHP login system that sends a confirmation email to activate your account but it doesn't send anything.
<?php
$error = NULL;
require "phpmailer/class.phpmailer.php";
require "phpmailer/class.smtp.php";
require "phpmailer/PHPMailerAutoload.php";
if(isset($_POST['submit'])) {
//Form Data GET
$u = $_POST['u'];
$p = $_POST['p'];
$p2 = $_POST['p2'];
$e = $_POST['e'];
//Throw Username too short error
if(strlen($u) < 5){
$error = "(!) Your username must be at least 5 characters.";
}elseif($p2 != $p) {
//Throw password pair error.
$error .= "(!) Your passwords do not match :/";
}else{
//200 [OK]
//Establish Connection to Database
$mysqli = NEW MySQLi('localhost','root','','test');
//Convert special chars.
$u = $mysqli->real_escape_string($u);
$p = $mysqli->real_escape_string($p);
$p2 = $mysqli->real_escape_string($p2);
$e = $mysqli->real_escape_string($e);
//Generate Verification Key
$vkey = md5(time().$u);
//Insert account into database
$p = md5($p);
$insert = $mysqli->query("INSERT INTO accounts(username,password,email,vkey)
VALUES('$u','$p','$e','$vkey')");
if($insert){
//Start PHPMailer
$mail = new PHPMailer(true);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 0; //No Debug. Set to 3 for verbose logging.
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; //Set to SSL to pass checks.
$mail->Host = "smtp.mail.com"; //Set to mail.com server, it has ssl, smtp, and it's free. If you'd like to use gmail, use smtp.gmail.com
$mail->Port = 465; //SSL/TLS Port for mail.com and gmail.com
//FILL WITH YOUR DETAILS
$mail->Username = 'example#mail.com';
$mail->Password = 'example';
//DON'T SET TO SENDER ADDRESS WILL FAIL SPF CHECKS!!!
$mail->SetFrom('example#mail.com', 'example');
$mail->AddAddress($e);
//Send the email.
$mail->Subject = trim("Email Verifcation");
$mail->isHTML(true);
//The Message
$mail->Body = '<h1>Hi, ' . $u . '!</h1><br><p>Activate<br><p>Alternatively copy and paste this link in your browser: <br> <b>Https://localhost' . $vkey . '';
echo "<center><div class='alert success'><strong>Successfully Registered!</strong> Please check your email.</div></center>";
}
//OOPS! Throw $error.
echo $mysqli->error;
}
}
?>
In the beginning, I require the files in my PHPMailer folder, then I start PHPMailer
It stresses me out. Idk the problem. If anybody knows the solution or knows a hint of why it doesn't work that would be great. Thanks.
HTML in same file
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
.alert {
padding: 20px;
background-color: #f44336;
color: white;
opacity: 1;
transition: opacity 0.6s;
margin-bottom: 15px;
font-family: Sans-Serif;
border-radius: 15px;
}
.alert.success {background-color: #4CAF50;}
.alert.info {background-color: #2196F3;}
.alert.warning {background-color: #ff9800;}
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: black;
}
</style>
</head>
<body>
<form method="POST" action="">
<table border="0" align="center" cellpadding="5">
<tr>
<td align="right">Username:</td>
<td><input type="TEXT" name="u" required/></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="PASSWORD" name="p" required/></td>
</tr>
<tr>
<td align="right">Repeat Password</td>
<td><input type="PASSWORD" name="p2" required/></td>
</tr>
<tr>
<td align="right">Email Address</td>
<td><input type="EMAIL" name="e" required/></td>
</tr>
<td colspan="2" align="center"><input type="SUBMIT" name="submit" value="Register" required/></td>
</table>
</form>
<center>
<?php
echo $error ;
?>
</center>
</body>
</html>
you can probably try this
i also had an error so i had to add this line before the host
$mail->SMTPOptions=array('ssl'=>array('verify_peer'=>false,'verify_peer_name'=>false,'allow_self_signed'=>false));
but if that does not work you can try trobleshooting like this
if($mail->Send()){
}else{
var_dump($mail);
die();
}
so once you get your error logs you can probably do a google or paste your error log and maybe we can help
Related
I'm trying to send emails using PHP Mailer. The site is uploaded to a free hosting. The error is displayed about failed SMTP connection. I'm hoping to someone that has expertise in this matter.
Here goes my code.
require '../extensions/phpmailer/PHPMailerAutoload.php';
$emailAddress = 'SampleEmail';
$password = 'Emailpassword';
$subject = 'Invitation to employee portal';
$message = '
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Invitation</title>
<body style ="background:#eee;">
<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable" style ="padding: 40px; max-width:640px;background-color:#f3f3f3;display:block;margin:0 auto; font-family:Lato, sans-serif; color:#626262;font-size:13px;line-height:22px;" width ="600">
<tbody>
<tr>
<td style ="background-color: #3552f2; padding: 34px 122px;">
<h1 width ="600" style ="max-width:600px;width:100%; text-align:center; color:#fff;">HRMS DHVTSU</h1>
</td>
</tr>
<tr>
<td style ="background-color: #ffffff; text-align: center; padding: 40px;">
<h1 style="font-size: 40px; color:#000; font-style: italic;">Sorry your account has been deactivated.</h1>
<br>
<p style ="color:#000; font-size: 16px;">For any questions please contact HR Department.</p>
<br>
<br>
</td>
</tr>
<tr>
<td style ="background-color: #3552f2; text-align: center; font-size: 16px; color: #fff;">
<p>© 2016. All rights reserved.</p>
</td>
</tr>
</tbody>
</table>
</body>';
$mail = new PHPMailer;
$mail->isSMTP();
// $mail->SMTPDebug = 2;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $emailAddress;
$mail->Password = $password;
$mail->setFrom('noreply#hrms.com', 'HRMS');
$mail->addReplyTo('johndoe#gmail.com', 'HRMS');
$mail->addAddress($email);
$mail->Subject = $subject;
$mail->msgHTML($message);
if (!$mail->send()) {
// $error = "Mailer Error: " . $mail->ErrorInfo;
// echo '<script>alert("'.$error.'");</script>';
return false;
}else {
$query = 'Update employee_has_credentials set status = '.self::STATUS_INACTIVE.' where id= '.$id.'';
$result = $this->con->prepare($query);
$result->execute(array($id));
if($result->rowCount()){
return true;
}else{
return false;
}
}
Possible duplicate of PHP Mailer issue use that code and it will fix your problem, because you have not added following code:
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php'
or go to above link more description you can see from that answer.
I'm trying to send data from database in the form of a HTML table when user click submit button. I'm able to receive the email but only table received. It doesn't seem database data. I want to email a table with data in database. Here is my code.
<?php
require '../Mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
//$mail->SMTPSecure = 'tls';
//$mail->SMTPAuth = true;
$mail->Host = '';
$mail->Port = ;
$mail->Username = '';
$mail->Password = '';
$mail->setFrom('');
$mail->addAddress('');
$mail->isHTML(true);
$mail->Subject = 'Student data';
$body = '<html>
<head>
<title></title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
text-align: left;
padding: 8px;
color:black
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<?php
$username = "root";
$password = "";
$host = "localhost";
$connector = mysqli_connect("$host,$username,$password");
or die("Unable to connect");
echo "Connections are made successfully::";
$selected = mysqli_select_db("school"," $connector");
or die("Unable to connect");
//execute the SQL query and return records
$result = mysqli_query("SELECT*FROM student ");
?>
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>age</th>
<th>class</th>
<th>address</th>
<th>comment</th>
</tr>
</thead>
<tbody>
<?php
while( $row = mysql_fetch_assoc( $result ) ){?>
<tr>
<td><?php echo $row["id"] ?></td>
<td><?php echo $row["name"]?></td>
<td><?php echo $row["age"] ?></td>
<td><?php echo $row["class"] ?></td>
<td><?php echo $row["address"] ?></td>
<td><?php echo $row["comment"] ?></td>
</tr>
<?php }
?>
</tbody>
</table>
<?php mysql_close($connector); ?>
</body>
</html> ';
$mail->Body = $body;
//send the message, check for errors
if (!$mail->send()) {
echo "ERROR: " . $mail->ErrorInfo;
} else {
echo "SUCCESS";
}
Thanks for everyone, who answer to my question. Here is the working code for my system.
<?php
require '../Mailer/PHPMailerAutoload.php';
$username = "root";
$password = "";
$host = "localhost";
$connector = mysql_connect($host,$username,$password)
or die("Unable to connect");
echo "Connections are made successfully::";
$selected = mysql_select_db("school", $connector)
or die("Unable to connect");
//execute the SQL query and return records
$result= mysql_query("SELECT * FROM student ORDER BY id DESC limit 1");
$mail = new PHPMailer;
$mail->isSMTP();
//$mail->SMTPSecure = 'tls';
//$mail->SMTPAuth = true;
$mail->Host = '';
$mail->Port = ;
$mail->Username = '';
$mail->Password = '';
$mail->setFrom('');
$mail->addAddress('');
$mail->isHTML(true);
$mail->Subject = 'Student Data';
$body = "<html>
<head>
<title>Student Data</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
text-align: left;
padding: 8px;
color:black
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>Age</th>
<th>Class</th>
<th>Address</th>
<th>comment</th>
</tr>
</thead>
<tbody>";
while( $row = mysql_fetch_assoc( $result ) ){
$body.= "<tr>
<td>".$row['id']."</td>
<td>".$row['name']."</td>
<td>".$row['age']."</td>
<td>".$row['class']."</td>
<td>".$row['address']."</td>
<td>".$row['comment']."</td>
</tr>";
}
$body.="</tbody></table></body></html>";
?>
<?php mysql_close($connector); ?>
<?php
$mail->Body = $body;
//send the message, check for errors
if (!$mail->send()) {
echo "ERROR: " . $mail->ErrorInfo;
} else {
echo "SUCCESS";
}
?>
Above your mysql connection data ($username, ...) is still a php opening tag.
Your code is all wrong, you're opening php tags inside a php tag.
Also you were using mysqli_ the wrong way, then trying to close with mysql_ .
Here, I fixed it for you:
<?php
require '../Mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
//$mail->SMTPSecure = 'tls';
//$mail->SMTPAuth = true;
$mail->Host = '';
$mail->Port = ;
$mail->Username = '';
$mail->Password = '';
$mail->setFrom('');
$mail->addAddress('');
$mail->isHTML(true);
$mail->Subject = 'Student data';
$body = '<html>
<head>
<title></title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
text-align: left;
padding: 8px;
color:black
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
';
$username = "root";
$password = "";
$host = "localhost";
$connector = mysqli_connect($host,$username,$password, "school");
or die("Unable to connect");
echo "Connections are made successfully::";
//execute the SQL query and return records
$result = mysqli_query($connector, "SELECT*FROM student ");
$body .='
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>age</th>
<th>class</th>
<th>address</th>
<th>comment</th>
</tr>
</thead>
<tbody>';
while( $row = mysqli_fetch_assoc($connector, $result ) ){
$body .= "<tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['age']}</td>
<td>{$row['class']}</td>
<td>{$row['address']}</td>
<td>{$row['comment']}</td>
</tr>"
}
$body .='
</tbody>
</table>
</body>
</html> ';
$mail->Body = $body;
//send the message, check for errors
if (!$mail->send()) {
echo "ERROR: " . $mail->ErrorInfo;
} else {
echo "SUCCESS";
}
Being a beginner, I am at a cross road on how to submit an error free form. Reference to the php file below, I have used 3 action settings with the following consequence:
Method 1
action = ""
This indicates the errors on same page whether there is an error or not.
Method 2:
action=""
This indicates the errors on same page whether there is an error or not.
Method 3:
action="User sch contact.php"
This opens a new page (User sch contact) with all the user input whether there is error or not.
Now I do not want the form submitted until every error is cleared by the user. Please how can I achieve this? Is there anything I am missing in php, sql, Mysql that will help me achieve this?
<!DOCTYPE html>
<html>
<head>
<title>PHP Exercise</title>
<style type="text/css">
body {font-family: Arial, Verdana, Helvetica,Sans-serif; padding: 0px;
margin-left: 50px;}
input:hover {background-color: rgb(250,250,150);}
.btn {padding: 5px 5px 5px 5px; background-color: rgb(240,240,240); font-
size: 12px; font-weight: bold; font-style: italic; border: 1px; }
.btn:hover {background-color: rgb(250,250,150);}
th {font-weight: bold; font-size: 14px; border: 1px; border-style: solid;
margin: 0px; border-spacing: 0px;}
.cdtl {text-align: left;}
td {font-weight: Normal; font-size: 14px; border: 1px; border-style: solid;
margin: 0px; border-spacing: 0px;}
.err {color: rgb(250,50,10); width: 200px; font-style: italic; border: 0px;
font-size: 14px;}
</style>
<script type="text/javascript">
var debugScript = true;
</script>
</head>
<?php
$username = $useraddy1 = $useraddy2 = $userfone = $useremail = $userurl
= "";
$firstgrade = $secondgrade = $thirdgrade = $fourthgrade = "";
$usernameerr = $useraddy1err = $useraddy2err = $userfoneerr =
$useremailerr = $userurlerr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["username"])) {
$usernameerr = "Name is required";
} else {
$username = test_input($_POST["username"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z0-9 ]*$/",$username)) {
$usernameerr = "Only alphanumerics and white space allowed";
} else {$usernameerr = "";}
}
if (empty($_POST["useraddy1"])) {
$useraddy1err = "Address is required";
} else {
$useraddy1 = test_input($_POST["useraddy1"]);
if (!preg_match("/^[a-zA-Z0-9 ]*$/",$useraddy1)) {
$useraddy1err = "Only alphanumerics and white space allowed";
} else {$useraddy1err = "";}
}
if (empty($_POST["useraddy2"])) {
$useraddy2err = "Address is required";
} else {
$useraddy2 = test_input($_POST["useraddy2"]);
if (!preg_match("/^[a-zA-Z ]*$/",$useraddy2)) {
$useraddy2err = "Only letters and white space allowed";
} else {$useraddy2err = "";}
}
if (empty($_POST["userfone"])) {
$userfoneerr = "Address is required";
} else {
$userfone = test_input($_POST["userfone"]);
if (!preg_match("/^[+0-9]*$/",$userfone)) {
$userfoneerr = "Only + numbers and white space allowed";
} else {$userfoneerr = "";}
}
if (empty($_POST["useremail"])) {
$useremailerr = "Email is required";
} else {
$useremail = test_input($_POST["useremail"]);
// check if e-mail address is well-formed
if (!filter_var($useremail, FILTER_VALIDATE_EMAIL)) {
$useremailerr = "Invalid email format";
}
}
if (empty($_POST["userurl"])) {
$userurl = "";
} else {
$userurl = test_input($_POST["userurl"]);
// check if URL address syntax is valid (this regular expression also
allows dashes in the URL)
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&##\/%?
=~_|!:,.;]* [-a-z0-9+&##\/%=~_|]/i",$userurl)) {
$userurlerr = "Invalid URL";
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h4>User Input</h4>
<form id="setUp" method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table id="contact" class="userInfo">
<tbody>
<tr>
<th class="cdtl">User Name:</td>
<td><input type="text" name='username' value="<?php echo $username;?>" />
</td>
<td class='err'><?php echo $usernameerr;?></td>
</tr>
<tr>
<th class="cdtl">Address1:Number, Street, City</td>
<td><input type="text" name='useraddy1' value="<?php echo $useraddy1;?>" />
</td>
<td class='err'><?php echo $useraddy1err;?></td>
</tr>
<tr>
<th class="cdtl">Address2:State, Country</td>
<td><input type="text" name='useraddy2' value="<?php echo $useraddy2;?>" />
</td>
<td class='err'><?php echo $useraddy2err;?></td>
</tr>
<tr>
<th class="cdtl">Telephone (International format)</td>
<td><input type="text" name='userfone' value="<?php echo $userfone;?>" />
</td>
<td class='err'><?php echo $userfoneerr;?></td>
</tr>
<tr>
<th class="cdtl">e-mail Address</td>
<td><input type="email" name='useremail' value="<?php echo $useremail;?>" />
</td>
<td class='err'><?php echo $useremailerr;?></td>
</tr>
<tr>
<th class="cdtl">Website (Optional)</td>
<td><input type="url" name='userurl' value="<?php echo $userurl;?>" /></td>
<td class='err'><?php echo $userurlerr;?></td>
</tr>
</tbody>
</table>
<br>
<input class="btn" type="submit" value="Submit" />
</form>
</body>
</html>
I have resubmitted this question in a different way. Basically, I was trying to validate a form on the client side. The best approach is to use both required and pattern in the input. With these 2, the form will not be submitted with a blank field & if user input does not follow the pattern. Further validation will of course be done on the server side for double assurance.
<form>
<b>User Id:<b><br>
<input id="userid" name="userid" type="text" required pattern="[A-Za-
z0-9.-_]{5,10}"><br>
<b>Password:<b><br>
<input id="userpswd" name="userpswd" type="password" required
pattern="[A-Za-z0-9&*]{8,20}"><br><br>
<b>SS Level:<b><br>
<input id="sslevel" name="sslevel" type="text" required pattern="[A-Za-z0-9]
{3,8}">
<input id='submit' type="submit" value="Submit form">
</form>
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.
<?php
// Script Error Reporting
//error_reporting(0);
// Require the form_functions to process the form
require('databaseConnect.php');
// Require the Email Class Functions
require("mailApp/class.phpmailer.php");
require("mailApp/class.smtp.php");
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPKeepAlive=true; // SMTP connection will not close after each email sent, reduces SMTP overhead
$mail->setFrom("No_Reply#girrawaagames.com", "Girrawaa Games"); // Valid email address from sender and Company name. Only Company name will be displayed
$mail->Subject='CASH Trader | The Spirit Stone'; // This adds the subject title in the subject line field
// Create a connection to MySQL and the database:
$con = mysqli_connect($hostname, $username, $password, $database);
// Check if the connection is active:
if(!$con) {
header('Location: alternate.php');
}
$result = mysqli_query($con, "SELECT fname, email FROM emails WHERE condition = 'condition'");
/* fetch associative array */
while ($row = $result->fetch_array()) {
$user['fname'][] = $row["fname"];
$user['email'][] = $row["email"];
}
$mail->AddAddress($user['email']);
$mail->Body="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<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;\">
<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\" style=\"border-collapse:collapse\">
<tr>
<td style=\"padding-top:20px; padding-right:0px; padding-bottom:30px; padding-left:0px; color:#153643; font-size:28px; font-weight:bold; font-family:Arial, Helvetica, sans-serif;\">
<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">
<tr>
<td class=\"header\" align=\"center\" bgcolor=\"#333333\" style=\"padding-top:10px; padding-right:10px; padding-bottom:10px; padding-left:10px; color:#153643; font-size:28px; font-weight:bold; font-family:Arial, Helvetica, sans-serif;\">
<img src=\"http://www.girrawaagames.com/img/logo.jpg\" style=\"color:#FFFFFF\" alt=\"Cash Trader Logo\" style=\"display:block; max-width:100%; height:auto;\" />
</td>
</tr>
</table>
</td>
</tr>
<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 " . $user['fname'] . "</b>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>";
print_r($user['fname']);
print_r($user['email']);
if ($mail->send()) {
$updateCampaign = "UPDATE emails SET column = 'value' WHERE email = '" . mysqli_real_escape_string($row['email']) . "'";
$results = mysqli_query($con, $updateCampaign);
}
// Clear all addresses and attachments for next loop
$mail->clearAddresses();
mysqli_free_result($result);
mysqli_close($con);
You need to concatenate the $useremail for it to have multiple emails.
$userEmail = '';
foreach($rows as $row) {
$userFname = $row["fname"];
$userEmail .= $row["email"] . ',';
}
It would probably be easier to pair these in an array..
foreach($rows as $row) {
$user['fname'][] = $row["fname"];
$user['email'][] = $row["email"];
}
Then you don't need the explode function later.
....
or better yet set it in the while loop, dont need foreach at all.
while($row = $result->fetch_array()){
$user['fname'][] = $row["fname"];
$user['email'][] = $row["email"];
}
Update:
<?php
// Script Error Reporting
//error_reporting(0);
// Require the form_functions to process the form
require('databaseConnect.php');
// Require the Email Class Functions
require("mailApp/class.phpmailer.php");
require("mailApp/class.smtp.php");
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPKeepAlive=true; // SMTP connection will not close after each email sent, reduces SMTP overhead
$mail->setFrom("No_Reply#girrawaagames.com", "Girrawaa Games"); // Valid email address from sender and Company name. Only Company name will be displayed
$mail->Subject='CASH Trader | The Spirit Stone'; // This adds the subject title in the subject line field
// Create a connection to MySQL and the database:
$con = mysqli_connect($hostname, $username, $password, $database);
// Check if the connection is active:
if(!$con) {
header('Location: alternate.php');
exit();
}
$result = mysqli_query($con, "SELECT fname, email FROM emails WHERE condition = 'condition'");
/* fetch associative array */
while ($row = $result->fetch_array()) {
$user['fname'][] = $row["fname"];
$user['email'][] = $row["email"];
}
foreach($user['email'] as $key => $email) {
$mail->AddAddress($email);
$mail->Body="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<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;\">
<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\" style=\"border-collapse:collapse\">
<tr>
<td style=\"padding-top:20px; padding-right:0px; padding-bottom:30px; padding-left:0px; color:#153643; font-size:28px; font-weight:bold; font-family:Arial, Helvetica, sans-serif;\">
<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">
<tr>
<td class=\"header\" align=\"center\" bgcolor=\"#333333\" style=\"padding-top:10px; padding-right:10px; padding-bottom:10px; padding-left:10px; color:#153643; font-size:28px; font-weight:bold; font-family:Arial, Helvetica, sans-serif;\">
<img src=\"http://www.girrawaagames.com/img/logo.jpg\" style=\"color:#FFFFFF\" alt=\"Cash Trader Logo\" style=\"display:block; max-width:100%; height:auto;\" />
</td>
</tr>
</table>
</td>
</tr>
<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 " . $user['fname'][$key] . "</b>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>";
if ($mail->send()) {
$updateCampaign = "UPDATE emails SET column = 'value' WHERE email = '" . mysqli_real_escape_string($row['email']) . "'";
$results = mysqli_query($con, $updateCampaign);
}
// Clear all addresses and attachments for next loop
$mail->clearAddresses();
mysqli_free_result($result);
mysqli_close($con);
}
You say you've looked everywhere... apart from code you already have! There is a mailing list example provided with PHPMailer that does exactly what you ask, correctly and efficiently.
In your code you're trying to send one message to 50 people, not 50 to 50, and it would also expose all addresses to all recipients, so this is generally a bad idea.
You've based your code on an obsolete example and are probably using an old version of PHPMailer, so get the latest.
I got this code and i get 2 errors in it. ive been going crazy for it for 2 days now and can figure it out. the admin account is activated in sql database is connected but it wont go past this screen.
Notice: Undefined index: username in
C:\xampp\htdocs\band\logincheck.php on line 8
Notice: Undefined variable: _REMOTE_ADDR in
C:\xampp\htdocs\band\logincheck.php on line 13
wrong username/password combination or account not yet activated
<?php
session_start();
header("Cache-control: private");
include 'includes/db_connect.php';
if (!$_SESSION['username'] || !$_SESSION['email']){
$username = $_POST['username'];
$password = $_POST['password'];
$username = strip_tags($username);
$password = strip_tags($password);
$ip = $REMOTE_ADDR;
$domain = $_SERVER['REMOTE_ADDR'];
$username=strtolower($username);
if((!$username) || (!$password)){
echo "You have not submitted one or more fields <br/>";
}else{
///check INFO
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1' LIMIT 1");
$login_check = mysql_num_rows($sql);
///other
if ($login_check > '1'){
ini_set(session.cookie_lifetime, "3600");
session_register('username');
$_SESSION['username'] = $username;
session_register('email_address');
$_SESSION['email_address'] = $email_address;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
$cool = gmdate('Y-m-d h:i:s');
mysql_query("UPDATE users SET lastlogin='$cool' WHERE username='$username'");
mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'");
mysql_query("UPDATE users SET ip='$domain' WHERE username='$username'");
?>
<meta http-equiv="Refresh" content=0;url=mb.php>
<?php
} else {
echo "wrong username/password combination or account not yet activated<br />
<br />";
include 'login.php';
}}}
?>
login.php
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
<head onload="window.status='Welcome To
Mafia'">
<META name="Maffia"
content="An Online Text Based Mafia Game.">
<META keywords="mafia, Mafia,
games, text game, base mafia, good games, internet
game, free games, fun, powermad, php games">
<title>Mafia
</title>
<link href="global.css" type="text/css"
rel="stylesheet">
<style type="text/css"
media="screen"><!--
#layer1 { visibility: visible; position: absolute; top:
100px; left: 100px; width: 158px; height: 102px }
#layer2 { visibility: visible; position: absolute; top:
465px; left: 100px; width: 69px; height: 21px }
--></style>
</head>
<body bgcolor="#000000" text="#FFFFFF" link="#FFFFFF"
vlink="#FFFFFF" alink="#FFFFFF"
onload="document.login.username.focus()">
<form id="login" action="logincheck.php" method="post"
name="login">
<center> <tf>
<center><img border="0" src="logo.jpg" ></center>
<tr>
<tr>
<font size="1"><b><font face="Verdana">Site Best Viewed And Played With FireFox www.mozilla.com
<br><br>Hello & Welcome To Bloodtown Mafia Online Multiplayer Game.
<br> This is not another mafia game but a mafia game with a difference,
<br> as you play you will realise this game to be very different to others out there.
<br> New features will be added regularly so that you can enjoy this gaming experience online.
<br>
<br>
</font></b></font>
</center>
</td>
</tr>
<tr>
<td height="30" width="196">
<div align="center"><font size="1"
face="Verdana"><b>Username:</b></font></div>
</td>
<div align="center"><font size="1"
<td width="200">
<input type="text" style="background-color:#000000;
font: 10pt verdana; color:#ffffff; border: 1px solid #900dbf;"
name="username" size="24">
</td>
</tr>
<tr>
<div align="center"><font size="1"
<td height="30">
<div align="center"><font size="1"
face="Verdana"><b>Password:</b></font></div>
</td>
<td>
<input type="password"
style="background-color:#000000; font: 10pt verdana;
color:#ffffff; border: 1px solid #900dbf;" name="password"
size="24">
</td>
</tr>
<tr>
<td colspan="2" valign="top" height="36">
<center>
<input type="submit" name="Submit" value="Submit">
</center>
</td>
</tr>
<tr><td colspan=2><center>
<center>
<font size=0.5 face=verdana><b>|| Register
|| Lost ||</b></font>
</center></center></td></tr>
</table>
</center>
</form>
</body>
</html>
You can replace following line with number 8 line
if (isset($_SESSION['username']) || isset($_SESSION['email'])){
There is no variabled defined as $REMOTE_ADDR
Please defined a variable before the if condition as defined below.
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
There will be no notice after these changes.
Please let me know, if you still finding any problems
Good luck.