Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 days ago.
Improve this question
I am trying to put the contents of an array into a table that can be used with PHP mail.
My code returns data from MySQL database and then gets called by another script to display the results.
I then need to insert the same data into a html table and send the tables and data in an email. The issue is when the email is sent
the only content in the email are the table headers, no data. Can anyone see why the data is not included in the email table?
$sql = "SELECT deviceType,deviceTypeCode,deviceDesc,deviceID, DeviceID19, DeviceLocation FROM FIDS_Hardware WHERE hotelid = '".$_SESSION['_amember_user']['hotelid']."' AND messageCount = 2";
$res = mysqli_query($conn, $sql) or die("Error: ".mysqli_error($conn));
$TotalRows_res = mysqli_num_rows($res);
$data = array();
while($row = mysqli_fetch_array($res)){
$DeviceDescription = $row['deviceDesc'];
$DeviceType = $row['deviceType'];
$DeviceTypeCode = $row['deviceTypeCode'];
$DeviceRefNo = $row['deviceID'];
$DeviceID19 = $row['DeviceID19'];
$DeviceLocation = $row['DeviceLocation'];
if($DeviceTypeCode == 5){
$DeviceRefNo = $DeviceRefNo;
} else {
$DeviceRefNo = $DeviceID19;
}
$data[] = array(
"DeviceDescription" => $DeviceDescription,
"DeviceType" => $DeviceType,
"DeviceRefNo" => $DeviceRefNo,
"DeviceLocation" => $DeviceLocation,
"TotalRows" => $TotalRows_res);
}
echo json_encode($data); // DATA DISPLAYED ON IN ANOTHER SCRIP[T
$subject = "Advisory:";
$to = $_SESSION['AdminEmail'];
$newOffline = array();
foreach($data as $data1){
$newOffline[] = implode(', ', $data1);
}
$newOffline = implode(" \n<br>", $newOffline);
$offline = $newOffline;
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers = "From: <support#mydomain.com>" . "\r\n" .
mail($to, $subject,$offline, $headers);
/* ALL OF THE ABOVE WORKS AND SEND DATA WHICH LOOKS LIKE THIS
EXBHX-Baskerville, Conference, 3, , 9
EXBHX-Bolton, Conference, 1, Conference centre, 9
EXBHX-Watt, Conference, 2, , 9
EXBHX-Brindley, Conference, 4, , 9
EXBHX-Cadbury, Conference, 5, , 9
EXBHX-Aston, Conference, 6, , 9
EXBHX-Main reception No2, Conference, WF2, Main reception, 9
EXBHX-Main reception No3, Conference, WF3, Conference centre, 9
EXBHX-Depart, Flightboard, WF6, Main reception, 9
*/
/* THIS IS THE TABLE I AM TRYING TO WORK WITH
$offline = '
echo "<tr><th>Description</th><th>Type</th><th>Device ID</th><th>Location</th></tr>";
foreach($data as $data1){
$newOffline[] = implode(', ', $data1);
$description = $newOffline[0];
$type = $newOffline[1];
$deviceid = $newOffline[2];
$location = $newOffline[3];
echo "<tr>";
echo " <td>"; echo $description; echo "</td>";
echo " <td>"; echo $type; echo "</td>";
echo " <td>"; echo $deviceid; echo "</td>";
echo " <td>"; echo $location; echo "</td>";
echo "</tr>";
}
'
;
*/
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers = "From: <support#mydomain.com>" . "\r\n" .
mail($to, $subject,$offline, $headers);
Related
I am trying to create a system that sends an e-mail to everyone of the users of my webpage.
It seems though that there are too many emails - about 2400 emails, to send for it to work.
Is there a smarter way, or a way to send 10 at a time or something like that?
Here is my code:
<?php
include('../../includingThis.php');
$fra = "ME <me#me.com>";
$emne = "";
$sql = "SELECT * FROM sendThese WHERE id=1";
if ($result = mysqli_query($con, $sql)) {
while($row = mysqli_fetch_assoc($result)) {
$emne = $row["subject"];
$message = $row["message"];
$mailsHere = $row["mailsHere"];
$til = explode(",", $mailsHere);
}
}
$besked = file_get_contents('sendThese.html');
$besked = str_replace("%%message%%", $message, $besked);
// HEADERS
$headers = "MIME-Version:1.0\r\n";
$headers .= "Content-type: text/html; charset=UFT-8\r\n";
$headers .= "From: ".$fra."\r\n";
// Mail til ejeren af siden
$mailsSend = 0;
foreach ($til as $value) {
mail($value,$emne,$besked,$headers);
$mailsSend++;
echo $value . "<br>";
sleep(2);
}
// Sender vi brugeren videre til en side
//header("Location: index.php");
echo "Done - " . $mailsSend . " e-mails sendt.";
die();
?>
I'm testing this code out. I assigned two reminders with test date and time values. Two reminders should be sent out to two different people. However when I run it, one will get an email containing their reminder, while the other person receives an email containing both his and the other reminder in the body of the email
Any help would be much appreciated.
Thanks!
<?
date_default_timezone_set("America/Los_Angeles");
//$trigger_date = date('h:i \P\S\T');
//$trigger_time = date('h:i A');
//test date and time
$trigger_date = date('Y-m-d');
$trigger_time = date('04:51');
$your_reminder = mysqli_query($conn,"SELECT * FROM reminders WHERE reminder_date = '$trigger_date' AND reminder_time = '$trigger_time'");
$todaydate = date("Y-m-d");
$row = $your_reminder->num_rows;
if ($row == 0 ){
echo "Nothing to Send</div>";
} else {
while($row = mysqli_fetch_array($your_reminder))
{ $reminder_owner = $row["reminder_owner"];
//echo $reminder_owner;
//echo "<br>Title:".$row["reminder_title"];
$send_owner = mysqli_query($conn,"SELECT * FROM admin WHERE username='$reminder_owner'");
$row_owner = mysqli_fetch_array($send_owner,MYSQLI_ASSOC);
$email = $row_owner["admin_email"];
$headers = 'From: TeamInfoPage';
$email_subject ="Reminder Test: ".$row["reminder_title"];
$reminder_details .= "Hi ".$row_owner["admin_fn"]."\n";
$reminder_details .= "Event: ".$row["reminder_title"]."\n";
// $reminder_details .= $row["tasks_notes"]."\n\n";
//Send out Reminder mail
'X-Mailer: PHP/' . phpversion();
#mail($email, $email_subject, $reminder_details, $headers);
}
echo "Success";}
?>
Plz reset the value of reminder_details in the loop for each mail..
You need to reset the reminder_details to blank between loop iterations.
Simply change these lines:
while($row = mysqli_fetch_array($your_reminder))
{ $reminder_owner = $row["reminder_owner"];
//echo $reminder_owner;
To this:
while($row = mysqli_fetch_array($your_reminder))
{ $reminder_owner = $row["reminder_owner"];
$reminder_details = "";
//echo $reminder_owner;
I got this code and it's old and I know I need to convert it to PDO (still learning) but I need to get this working right now.
I am trying to send multiple emails out based on the query. So in this particular query I get two results. So I need to send out two different emails to the group. If the query had 4 results, then I would need to send 4. Right now it is only sending the first result. How can I get it to loop through and send multiple emails.
Here is the code:
<?
// connection string ......
$production = "SELECT value1 FROM parameters WHERE name = 'IS_PRODUCTION' ";
$query = "SELECT accounts.username, email_activate.email, accounts.user_id, accounts.alt_id FROM accounts INNER JOIN email_activate ON accounts.user_id = email_activate.user_id WHERE dt_welcome = '0000-00-00 00:00:00' AND dt_start <= DATE_SUB(NOW(), INTERVAL 3 DAY)";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$message = "Hello ".$row['username'].", <br/><br/>";
$message .= "You recently subscribed to <bblah blah blah</b> ";
$message .= '(http://), ' ;
$message .= "the official ";
$message .= "source of <br /><br /> ";
if ($production == 'Y' ) {
$subject = "How can we Assist!";
$to = "".$row['email']."";
$result2 = mysql_query("UPDATE email_activate SET dt_welcome = NOW() WHERE user_id = '".$row['user_id']."' ");
} else {
$subject = "[TEST] Offer You Assistance";
$to = 'email1#email.com' . ', ';
$to .= 'email2#email.com ' . ', ';
$to .= 'email3#email.com';
$result2 = mysql_query("UPDATE email_activate SET dt_welcome = NOW() WHERE user_id = '".$row['user_id']."' ");
}
$headers = "Content-Type: text/html; charset=utf-8\r\n";
$queryEmail = "SELECT alt_id FROM lookup_roles WHERE spec_tag = 'public_email'";
$result3 = mysql_query($queryEmail) or die(mysql_error());
while ($row12 = mysql_fetch_array($resul3t)) {
mail($to, $subject, $message, $headers, "-f ".$row12[alt_id]."");
}
}
?>
So I fixed it, the above code works just fine. I forgot to use a different $result variable ---> Changed it from $result to $result3, this way it doesn't blank out the previous result which is why I was only getting 1 email. I knew it was something simple, just couldn't see it.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
For whatever reason, whenever I submit the form, it doesn't add the inputted data to the database. It was working before... Which I think is what's frustrating me the most. I came back to it a couple of hours later, and surprise! Not inserting new rows into the database. Perhaps there's a slight error I may have done subconsciously by accident? Nothing stands out to me, though. :(
refer.html: http://pastebin.com/d1xQUJLR
generator.php: http://pastebin.com/CE2UX8zs
main.js: http://pastebin.com/CSQh9DKs
Just fixed some bugs in your code ;)
<?php
include_once "access.php";
$ref_email = $_POST["tf_ref_email"];
$ref_username = $_POST["tf_ref_username"];
$ref_ign = $_POST["tf_ref_ign"];
$access = new Access();
$crux = $access->getCrux();
$anchor = $access->getAnchor();
$user = $access->getUser();
try {
$pdo = new PDO($anchor, $user, $crux);
$stq = "INSERT INTO referred_users
(ref_id, ref_email, ref_username, ref_ign, ref_awarded, new_email, new_awarded)
VALUES (:ref_id, :ref_email, :ref_username, :ref_ign, :ref_awarded, :new_email, :new_awarded)";
for($i = 0; $i < min(count($_POST["emails"]), 10); $i++) {
$ref_id = $_POST["ref_ids"][$i];
$new_email = $_POST["emails"][$i];
$new_ref_id = checkId($ref_id, $pdo);
$query = $pdo->prepare($stq);
$results = $query->execute(
array(
':ref_id' => $new_ref_id,
':ref_email' => $ref_email,
':ref_username' => $ref_username,
':ref_ign' => $ref_ign,
':ref_awarded' => '0',
':new_email' => $new_email,
':new_awarded' => '0'
)
);
$to = $new_email;
$subject = "Check out this AMAZING Minecraft RP Server!";
$message = "You have been invited to join " . $ref_ign . " in Arithia! Enter your Referral ID in the provided link to get a head start on your first character!" . "\n";
$message .= "Referral ID: " . $new_ref_id . "\n";
$message .= "Redeem Rewards: " . "http://www.graphicgoldfish.com/referral/referral.html" . "\n";
$message .= "By redeeming your referral, you will get:" . "\n";
$message .= "- 300 Credit Points" . "\n";
$message .= "- 50 Ducats" . "\n";
$message .= "- 25 Cooked Beef" . "\n";
$message .= "- Identification Tome" . "\n";
$message .= "We look forward to seeing you in Arithia! For more information, visit: http://www.arithia.com" . "\n";
$headers = "From: $ref_email";
mail($to, $subject, $message, $headers);
}
} catch(PDOException $e) {
echo 'Error: ' . $e->getMessage();
}
function checkId($id, $con) {
$stmt = $con->prepare("SELECT ref_id FROM referred_users WHERE ref_id = :ref_id");
$stmt->bindParam(':ref_id', $id);
$stmt->execute();
if($stmt->rowCount() > 0) {
$new_id = (string)rand(1000000, 9999999);
return checkId($new_id, $con);
}
return $id;
}
I had asked a question yesterday about sending an email every three days which was answered so I'm not sure if I should create a new one or add to the old.
The check is working fine as I get the correct ouptut on screen, but when I try to send the email it is only sending one result. I've tried foreach loops, putting the mail function in different places none of which seem to work. My code is below, I've removed most of the message parts as they are just long tables.
**UPDATE ****
I've added the recipients array into the while loop and also set $subject and $headers to empty values before adding values. This has worked.
$sql = "SELECT * FROM bookings " .
"WHERE DATE(date) > DATE(NOW()) " .
"AND dateofquote != '' " .
"AND email != '' " .
"AND confirmed = 0";
$result = mysql_query($sql);
$num_rows = mysql_numrows($result);
$today = date('Y-m-d');
if ($num_rows) {
while ($row = mysql_fetch_array($result)) {
$recipients = array(); // Updated
$id = $row['id'];
// rest of rows from db
$date_time1 = new DateTime($today);
$date_time2 = new DateTime($date_of_quote);
$interval = $date_time1->diff($date_time2);
$diff = $interval->format('%a');
if ($diff % 3 == 0) {
if ($type == 'W') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Weddding Email</h1>'.$message.'<br />End Wedding<br /><br /><hr>';
// tried to send email from here for this option
}
elseif ($type == 'D') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Debs Email</h1>'.$message.'<br />End Debs<br /><br /><hr>';
// tried to send email from here for this option
}
elseif ($type == 'CR') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Country Run Email</h1>'.$message.'<br />End Country Run<br /><br /><hr>';
// tried to send email from here for this option
}
elseif ($type == 'H') {
$message = '<table width="95%" border="0" cellspacing="0" align="center" style="border:1px solid #999;">';
// rest of table
echo '<h1>Hourly Email</h1>'.$message.'<br />End Hourly<br /><br /><hr>';
// tried to send email from here for this option
}
} else {
echo 'something went wrong';
}
$recipients[] = $email;
$subject = ''; // Updated
$headers = ''; // Updated
$subject .= "An $type_value Enquiry has been received from company.ie";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Name <email#email.com>' . "\r\n";
foreach($recipients as $to){
if(mail($to, $subject, $message, $headers)) {
echo "E-Mail Sent to ";
echo $to.'<br />';
} else {
echo "There was a problem";
}
}
}
}
Try like this inside your while loop. Your mail content is inside the while loop, but you are trying mail function outside the while loop, so it is sending last content to all your mails in $recipients array.
$subject='';
$headers='';
$subject .= "An $type_value Enquiry has been received from company.ie";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Absolute Limos <email#email.com>' . "\r\n";
mail($email, $subject, $message, $headers);
your problem lies here:
$recipients[] = $email;
You create your email array outside your loop, thus you only get the last email address value.
Put it in your
while ($row = mysql_fetch_array($result)) {