I have created send_bday_email.php which send birthday email 2 weeks prior to customer's birthday.
<?php
$today = date('Y-m-d');
$todayMD = date('m-d');
include_once "../../mysqli_connect.php";
$sql= mysqli_query($dbc, "SELECT * FROM Customer_Info");
$mail_body = '';
while ($row= mysqli_fetch_array($sql)) {
$id = $row["id"];
$email = $row["email"];
$birthday = $row['birthday'];
$bday = new DateTime($birthday);
$bday->sub(new DateInterval('P14D'));
$twoWeekbday = $bday->format('m-d');
if ($todayMD==$twoWeekbday) {
if(empty($row["firstName"])){
$name = 'Customer';
} else {
$name = $row["firstName"];
}
$mail_body = file_get_contents('../forms/bday_email_form.html');
}
}
This is my part of code which has two weeks prior and if customer's two week prior is equal to today send birthday email.
If I run this code daily using cron job, will it send emails perfectly?
I wanted to make sure before I actually test it out with my customer.
Related
I'm trying to make a system where an administrator can add multiple people at the same time into a database. I want this system to prevent the administrator from adding people with email addresses already existing in the database.
IF one of the emails in the _POST["emailaddress"] matches with one of the emailaddresses in the db, the user should get a message saying one of the emails already exists in the database. To achieve this, I've tried using the function array_intersect(). However, upon doing so I get a warning saying:
Warning: array_intersect(): Argument #2 is not an array in ... addingusers.php on line 41
At first i thought it had something to do with the fact my second argument was an associative array, so I tried the function array_intersect_assoc, which returns the same warning. How can I solve this?
The code on addingusers.php
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors',1);
$conn = mysqli_connect('localhost','*','*','*');
$condition = false; // this is for the other part of my code which involves inserting the output into db
$name = $_POST["name"];
$affix = $_POST["affix"];
$surname = $_POST["surname"];
$emailaddress = $_POST["emailaddress"];
$password = $_POST["password"];
//amount of emailaddresses in db
$checkquery2 = mysqli_query($conn, "
SELECT COUNT(emailaddress)
FROM users
");
$result2 = mysqli_fetch_array($checkquery2);
// the previously mentioned amount is used here below
for($i=0; $i<$result2[0]; $i++){
// the actual emails in the db itself
$q1 = mysqli_query($conn, "
SELECT
emailaddress
FROM
users
");
// goes through all the emails
$result_array1 = array();
while ($row1 = mysqli_fetch_assoc($q1)) {
$result_array1[] = $row1;
}
$query1 = $result_array1[$i]["emailaddress"];
}
// HERE LIES THE ISSUE
for($i=0; $i<count($emailaddress); $i++){
if (count(array_intersect_assoc($emailaddress, $query1)) > 0) {
echo "One of the entered emails already exists in the database...";
echo '<br><button onclick="goBack()">Go Back</button>
<script>
function goBack() {
window.history.back();
}
</script><br>';
$condition = false;
}
else{
$condition = true;
}
}
EDIT
as the comments point out, $query1 is indeed not an array it is a string. However, the problem remains even IF i remove the index and "[emailaddress]", as in, the code always opts to the else-statement and never to if.
$query1 is not an array, it's just one email address. You should be pushing onto it in the loop, not overwriting it.
You also have more loops than you need. You don't need to perform SELECT emailaddress FROM users query in a loop, and you don't need to check the intersection in a loop. And since you don't need those loops, you don't need to get the count first.
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors',1);
$conn = mysqli_connect('localhost','*','*','*');
$condition = false; // this is for the other part of my code which involves inserting the output into db
$name = $_POST["name"];
$affix = $_POST["affix"];
$surname = $_POST["surname"];
$emailaddress = $_POST["emailaddress"];
$password = $_POST["password"];
$q1 = mysqli_query($conn, "
SELECT
emailaddress
FROM
users
");
// goes through all the emails
$result_array1 = array();
while ($row1 = mysqli_fetch_assoc($q1)) {
$result_array1[] = $row1['emailaddress'];
}
$existing_addresses = array_intersect($emailaddress, $result_array1);
if (count($existing_addresses) > 0) {
echo "Some of the entered emails already exists in the database: <br>" . implode(', ', $existing_addresses);
echo '<br><button onclick="goBack()">Go Back</button>
<script>
function goBack() {
window.history.back();
}
</script><br>';
$condition = false;
}
else{
$condition = true;
}
I am creating an android application which uses the PHP/MySQL database employee details.
my database contains the details like schedule date and hours etc,
I have two questions
I want to check the database at regular interval of time like if there is any change in schedule date and hours notify the user.
how to send the notification to the users when the admin set the scheduled date and hours for an employee or modify the hours in database.
send notification like
"your schedule has been created"
or
"your schedule hour has been changed"
But I should not use Firebase and gcm method.
Is there is any way to send the notification to the user without using Firebase and gcm?
this is my PHP file which will receive the data from the database and send to android application.
<?php
require "init.php";
$name = $_POST["name"];
$password = $_POST["password"];
//$name = "rajesh";
//$password = "1995";
$Sql = "SELECT * FROM `user_info`
WHERE `name`='".$name."' AND
`password`='".$password."';";
$result = mysqli_query($con, $Sql);
$retrive = array();
while($row = mysqli_fetch_array($result))
{
$user_id = $row['id'];
$sql = "SELECT id, ScheduleDate, StartTime,Endtime, Hours,Employeeid
FROM empdet WHERE Employeeid ='".$user_id."' ";
$result = $con->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
$id=$row["id"].
$date=$row["ScheduleDate"];
$start=$row["StartTime"];
$end=$row["Endtime"];
$hour=$row["Hours"];
$Employeeid=$row["Employeeid"];
list($year,$month,$day) = split("-",$date);
$data[] = array("year"=>$year,
"month"=>$month,
"day"=>$day,
"StartTime"=>$start,
"Endtime"=>$end,
"Hours"=>$hour );
}
$response = $data;
}
else
{
$data=1;
$response = $data;
}
}
if($response==null )
{
echo "USERNAME/PASSWORD IS INCORRECT";
}
else
{
if($response==1)
{
echo "NO SCHEDULE FOUND";
}
else
{
echo json_encode(array("user_data"=> $response));
}
}
?>
here I want to check the database for change or modify at the regular interval, and send the notification to the android application of the particular user without using gcm and firebase.
i was using this codes to send newsletter to members , now the problem is that when i send emails it doesn't send . i tracked the emails in cpanel and found that the email address has the word 'array' before it . that means that when i send to 'email#domain.com' it changes to 'arrayemail#domain.com'. and this is the code :
<?php
include("../include/config.php");
include_once("../include/functions/import.php");
verify_login_admin();
$adminurl = $config['adminurl'];
$thebaseurl = $config['baseurl'];
$sql = "SELECT USERID, username, email FROM members";
$executequery = $conn->Execute($sql);
$results= $executequery->getrows();
if($_POST['submitform'] == "1")
{
if(isset($_POST['USERID']))
{
foreach($_POST['USERID'] as $key)
{
$subject = $_POST['subject'];
$sendername = $config['site_name'];
//$bodymessage = "Dear " . $_POST['username'];
//$sendmailbody = "HI". $results[$i]. $key . $results[$i].$_POST['username'] .",";
$sendmailbody .= $_POST['message'];
$sendmailbody .= "";
$from = $config['site_name'].'<'.$config['site_email'].'>';
$sendto = $results[$i]. $key.',';
mailme($sendto,$sendername,$from,$subject,$sendmailbody,$bcc);
}
}
$message = "E-Mails / Newsletters sent successfully.";
Stemplate::assign('message',$message);
}
$mainmenu = "7";
$submenu = "2";
$bodymsg = $_POST['message'];
Stemplate::assign('subject',$subject);
Stemplate::assign('bodymsg',$bodymsg);
Stemplate::assign('mainmenu',$mainmenu);
Stemplate::assign('submenu',$submenu);
Stemplate::assign('results',$results);
STemplate::display("administrator/global_header.tpl");
STemplate::display("administrator/mass_newsletter.tpl");
STemplate::display("administrator/global_footer.tpl");
?>
It looks like you are getting all rows from your query:
$results= $executequery->getrows();
^ plural
But you never actually loop over all rows, so $results[$i] will contain one complete row from the result set: An array containing the USERID, username and email.
And when you concatenate an array with a string, the array will result in the text array.
And that is assuming that $i is an integer but in your code it is not defined at all.
You probably want to loop over the result-set somewhere and if you use a foreach you will not need the $i variable at all:
foreach ($results as $result) {
// Build your e-mail addresses string?
...
}
I am building a script that checks for dates that will expire within 7 days and sends out a email reminder to the admin owner and also update a date notified column in the database, I have got it sort of working, it updates the date notified column and sends the email out but it only lists one date in the email where as there should be two as I set two dates to expire within 7 days, can anyone help please, below is the coding I have
<?php
$db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"") or die(mysqli_error($db));
if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
} else {
/*SUCCESS MSG*/
echo '';
}
$sqlCommand = "SELECT
u.id
, domain_name_owner
, url
, DATE_FORMAT(domain_expiry_date, '%e %M %Y') as domain_expiration_date
, domain_owner_email
FROM websites u
WHERE domain_expiry_date BETWEEN CURDATE() AND CURDATE()+INTERVAL 7 DAY
";
$query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
//fetch the data from the database
while ($row = mysqli_fetch_array($query)) {
$arr_ids[] = $row['id'];
$email = '';
$headers = "From: noreply#domain.co.uk\r\n";
$subject = "Domain Name Expiry Date(s)";
$message = '';
$id = $row['id'];
$owner = $row['domain_name_owner'];
$email = $row['domain_owner_email'];
$message = "Domain Name Owner: {$row['domain_name_owner']} \n\n";
$message .= "Your Domain Name {$row['url']} expiry date is: {$row['domain_expiration_date']}\n";
$to = $email;
$sendmail = mail($to, $subject, $message, $headers);
if ($sendmail) {
echo nl2br($message);
echo "<b>Email Successfully Sent</b><br><br>";
} else {
echo "<b>Error in Sending of Email to $to</b><br><br>";
}
}
if (isset($arr_ids)){
$sql = "UPDATE websites SET date_notified_of_domain_expiry = NOW() WHERE id IN (";
$sql .= implode("," , $arr_ids);
$sql .= ");";
print $sql;
}
//$db->query($sql);
$db->query($sql) or die(mysqli_error($db));
// Free the results
mysqli_free_result($query);
//close the connection
mysqli_close($db);
?>
Thank you in advance
Your Script is working fine, it should send one email per expiry date (based on your code), if the domain owner owns two domains, he will receive two separate emails that each one of them is related to a certain domain.
If you want to send the two domains on the same email, use the below script:
<?php
$db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!");
// Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
mysqli_select_db($db,"") or die(mysqli_error($db));
if (mysqli_connect_error()) {
die ('Failed to connect to MySQL');
} else {
/*SUCCESS MSG*/
echo '';
}
$sqlCommand = "SELECT
u.id
, domain_name_owner
, url
, DATE_FORMAT(domain_expiry_date, '%e %M %Y') as domain_expiration_date
, domain_owner_email
FROM websites u
WHERE domain_expiry_date BETWEEN CURDATE() AND CURDATE()+INTERVAL 7 DAY
";
$query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
//fetch the data from the database
$message = '';
$email = '';
$prev_Email ='';
while ($row = mysqli_fetch_array($query)) {
$arr_ids[] = $row['id'];
$prev_Email = $email;
$headers = "From: noreply#domain.co.uk\r\n";
$subject = "Domain Name Expiry Date(s)";
$id = $row['id'];
$owner = $row['domain_name_owner'];
$email = $row['domain_owner_email'];
if($prev_Email == ""){
$prev_Email = $email;
}
if($email == $prev_email && $email != ""){
$message. = "Domain Name Owner: {$row['domain_name_owner']} \n\n";
$message .= "Your Domain Name {$row['url']} expiry date is: {$row['domain_expiration_date']}\n";
}else{
if($prev_Email != ""){
$to = $prev_Email;
$sendmail = mail($to, $subject, $message, $headers);
if ($sendmail) {
echo nl2br($message);
echo "<b>Email Successfully Sent</b><br><br>";
} else {
echo "<b>Error in Sending of Email to $to</b><br><br>";
}
$message = "Domain Name Owner: {$row['domain_name_owner']} \n\n";
$message .= "Your Domain Name {$row['url']} expiry date is: {$row['domain_expiration_date']}\n";
}
}
}
if (isset($arr_ids)){
$sql = "UPDATE websites SET date_notified_of_domain_expiry = NOW() WHERE id IN (";
$sql .= implode("," , $arr_ids);
$sql .= ");";
print $sql;
}
//$db->query($sql);
$db->query($sql) or die(mysqli_error($db));
// Free the results
mysqli_free_result($query);
//close the connection
mysqli_close($db);
?>
i want to send the mail , when product got expire from before and ondate and after day, in php i was used datediff mysql function with php, but if product expire date comes like 31-1-2012 , the differ value is not suit for my coding , plz help how to solve it ,
This is my coding
<?php
$sql = mysql_query("SELECT * FROM supplier_product_det");
$results = mysql_num_rows($sql);
//echo '<script>alert("'.$results.'")</script>';
if ($results > 0)
{
for($i=0;$i<$results;$i++)
{
while($rows = mysql_fetch_array($sql))
{
/* print_r($rows['expired_on']);?><br /> <?*/
$exdate = $rows['expired_on'];
$curdate = date('Y-m-d');
$datedif = mysql_query("select datediff('".$curdate."','".$exdate."')");
while( $date = mysql_fetch_array($datedif) )
{
//echo $date['0'];
//echo $rows['pro_code'];
if (($date['0'])== 1)
{
if(($rows['mailcount'])!== $curdate)
{
$to = $rows['supplier'];
$subject = "Product Expire Intimation";
$message = "Dear Mr/Miss/Mrs
The Following Your Product Expired
Product Code:".$rows['pro_code']."
Product Name:".$rows['product_name']."
Product Expire Date:".$rows['expired_on']."";
$from = "tone#bgrow.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$checkdate = mysql_query("update supplier_product_det set mailcount ='".$curdate."' where id='".$rows['id']."'") or die(mysql_error());
}
//echo $rows['supplier'];
}
if (($date['0'])== 0)
{
if(($rows['mailcount'])!== $curdate)
{
$to = $rows['supplier'];
$subject = "Product Expire Intimation";
$message = "Dear Mr/Miss/Mrs
The Following Your Product Expired
Product Code:".$rows['pro_code']."
Product Name:".$rows['product_name']."
Product Expire Date:".$rows['expired_on']."";
$from = "tone#bgrow.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$checkdate = mysql_query("update supplier_product_det set mailcount ='".$curdate."' where id='".$rows['id']."'") or die(mysql_error());
}
//echo $rows['supplier'];
}
if (($date['0'])== -1)
{
if(($rows['mailcount'])!== $curdate)
{
$to = $rows['supplier'];
$subject = "Product Expire Intimation";
$message = "Dear Mr/Miss/Mrs
The Following Your Product will Expire Today
Product Code:".$rows['pro_code']."
Product Name:".$rows['product_name']."
Product Expire Date:".$rows['expired_on']."";
$from = "tone#bgrow.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$checkdate = mysql_query("update supplier_product_det set mailcount ='".$curdate."' where id='".$rows['id']."'") or die(mysql_error());
}
//echo $rows['supplier'];
}
}
}
}
}
?>
Write your second select query as follows
SELECT DATEDIFF($exdate, CURRENT_DATE) as diff;
Also, no need to write separate select query you can get same column in first query itself as
SELECT column1, column2, column3, DATEDIFF(expired_on, CURRENT_DATE) as diff
FROM supplier_product_det
You may need to change position of expired_on and CURRENT_DATE to get correct diff value
Try something like this...
PHP: $now = date('Y-m-d', strtotime('now'));
-
SQL: WHERE $now >= DATE_FORMAT(expires, "%Y-%m-%d")