i need to send an email with the below query but cannot get it to send? what am i doing wrong? i have removed the connect details. i just get a HTTP ERROR 500
require "defaultincludes.inc";
$to_email = "antham1616#gmail.com";
$subject = "Tomorrow Jobs";
$body = "$sql =
Select * From mrbs_entry Where from_unixtime(start_time, '%Y-%m-%d') = CURDATE() + INTERVAL 1 DAY AND driver = 'Kim Emery' ORDER by start_time asc";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<br> <strong>Bus:</strong> ".$row["room_id"]. " Driver: ".$row["driver"]. " Trip: ".$row["name"] . " Fee: ".$row["fee"] . " <tr>";
{echo "<br> Time: " . $row["pickup_time"]. " Name: ". $row["pickup_address"]. " Going: ". $row["pickup_1_going"]. "<br>";}
}
} else {
echo "0 results";
}
echo "<img src='images/bus checks.jpg' alt='checks' />";
$headers = "From: office#ndct.co.uk";
if ( mail($to_email, $subject, $body, $headers)) {
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
?>```
There's probably a syntax error somewhere in your code. Have a look in the error log.
This like looks weird:
$body = "$sql =
Related
I'm trying to display all the rows in my data from my data of my specific user but its only displaying 1 row and not updating.
the code is -
$user = $_SESSION["username"];
$sql = "SELECT * FROM transactions WHERE sender OR receiver = ?";
if ($sql = $conn->prepare($sql)) {
$sql->bind_param("s",$user);
if ($sql->execute()) {
$result = $sql->get_result();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<br> sender: ". $row["sender"]. " - receiver: ". $row["receiver"]. " -amount:" . $row["amount"] . "<br>";
}
}
$sql->close();
$conn->close();
}else{ echo "0 result"; }
}
?>
You are using wrong SQL formation & passing just receiver value. I suggest below changes:
Replaced
1) WHERE sender OR receiver = ? with WHERE sender=? OR receiver = ?
2) $sql->bind_param("s",$user); with $sql->bind_param("ss",$user,$user);
$user = $_SESSION["username"];
$sql = "SELECT * FROM transactions WHERE sender=? OR receiver = ?";
if ($sql = $conn->prepare($sql)) {
$sql->bind_param("ss",$user,$user);
if ($sql->execute()) {
$result = $sql->get_result();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<br> sender: ". $row["sender"]. " - receiver: ". $row["receiver"]. " -amount:" . $row["amount"] . "<br>";
}
}
$sql->close();
$conn->close();
}else{ echo "0 result"; }
}
I am trying to send email of which one of the data is from database, i tried to look on some post here in stack-overflow but they were different;
I tried to send without the data from the database and it works fine,but after adding database fetch its not working
<?php
include 'include/connect.php';
if (isset($_POST['book2'])) {
$id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = "SELECT room_price FROM room_details WHERE id='$id';";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$room_price = $row['room_price'];
$email = $_POST['email'];
$room_type = $_POST['room_type'];
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];
$adults = $_POST['adults'];
$children = $_POST['children'];
$mailTo = "booking#johndoexxx.com";
$headers = "Guest sent e-mail from: " . $email;
$txt = "New booking received, room for " . $adults . " adults and " . $children . " child / children, reservation starts on " . $checkin . " up to " . $checkout . " whereby " . $room_type . " room is selected, Please respond to the sender!";
$heading = "New Booking!";
mail($mailTo, $heading, $headers, $txt);
header("Location: index.php?bookingsent");
}
}
} else {
echo "Booking failed to process!, observe your inputs carefully!";
}
?>
was expecting it will fetch data from form and will send the data into the targeted email.
i have wrote a php script to send an emails.In this script it checks whether current date is equal with the emailfly_date and email is = o.if that satisfies email will sent to the user.this script is working for one user at a one time.that if database has five records that that matches current criteria it sends the email only to the last id.what is the reason for this?
id
250
251
252
253
it will send the email only to the ID 253.but not to the others.
Here is mycode
<?php
include_once 'dbconnect.php';
$query = "SELECT ID,email, emailfly_date, CURRENT_DATE AS nowtime FROM xxx WHERE reqnum = '' AND email_sent = '0'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$regid = $row['ID'];
$activemail= $row['nowtime'];
/*echo $regid . '<br />';
echo $activemail. '<br />';*/
}
$query = mysql_query("SELECT ID, email, reqnum, emailfly_date, email_sent FROM xxx WHERE ID = '$regid' AND emailfly_date = '$activemail'");
$rowdata = mysql_fetch_array($query);
$ID = $rowdata['ID'];
$email = $rowdata['email'];
$reqnum = $rowdata['reqnum'];
$emailfly_date = $rowdata['emailfly_date'];
$email_sent = $rowdata['email_sent'];
if ($reqnum != '') {
/* echo "not sucess";*/
} elseif ($email_sent == '1') {
/* echo "email already sent";*/
} elseif ($email_sent == '1' && $reqnum != '') {
/* echo "no way to send";*/
}
elseif($email_sent == '0' && $reqnum == '' ){
$ulink = "http://xxx.eewfewt.net/tttt/yyyy.php?ID=$regid";
$to = $email;
$subject = 'hoo'; // Give the email a subject
$message = '
Thanks for Using Trial Version!
If You Wish to Continue with the Monthly Paid Package.
------------------------
Click Below
Site Renewal link: ' . $ulink . '
'.$emailfly_date.'
------------------------ ';
$headers .= 'From:werwerwer.aaa.net' . "\r\n";
$headers .= 'Bcc:ewrwerer.aaa.net' . "\r\n";
mail($to, $subject, $message, $headers);
$upadtequery = mysql_query("UPDATE xxx SET email_sent ='1' WHERE ID = '$regid'");
echo "sucess";
}
else{
echo "bye";
}
?>
From $query = mysql_query(.....bla...bla... to last else{
echo "bye";
} Put all this inside your while loop.
Also if you fetch data from same table try to use single query.
mysql_() is depreciated now. So try to use mysqli_()
include_once 'dbconnect.php';
$query = "SELECT ID,email, emailfly_date, CURRENT_DATE AS nowtime FROM xxx WHERE id in ('250','251','252','253') AND email_sent = '0'";
$result = mysql_query($query) or die(mysql_error());
while($rowdata = mysql_fetch_array($result))
{
$ID = $rowdata['ID'];
$email = $rowdata['email'];
$reqnum = $rowdata['reqnum'];
$emailfly_date = $rowdata['emailfly_date'];
$email_sent = $rowdata['email_sent'];
$ulink = "http://xxx.eewfewt.net/tttt/yyyy.php?ID=$regid";
$to = $email;
$subject = 'hoo'; // Give the email a subject
$message = '
Thanks for Using Trial Version!
If You Wish to Continue with the Monthly Paid Package.
------------------------
Click Below
Site Renewal link: ' . $ulink . '
'.$emailfly_date.'
------------------------ ';
$headers .= 'From:werwerwer.aaa.net' . "\r\n";
$headers .= 'Bcc:ewrwerer.aaa.net' . "\r\n";
mail($to, $subject, $message, $headers);
$upadtequery = mysql_query("UPDATE xxx SET email_sent ='1' WHERE ID = '$ID'");
echo "sucess";
}
Ok what i want is to go through database and send an email to every email whose database stored time and date is lower then current date and whose sent value is 0. Whats working is it goes through the loop of email and sends the emails however what i want to do is to set sent value in the database from 0 to 1 so that if i ran the program in the future it wont send the emails again to people that i already have send an email. i tried updating the send value to 1 inside my while loop but when i execute my file it stops after just one email, so it doesn't loop through database
<?php
include_once("db.php");
$date = new DateTime();
//echo $date->format('Y-m-d H:i:s')
$query = "SELECT timedate, email, sent, msgid FROM mailer";
$result = mysql_query($query);
echo "<table>";
while($row = mysql_fetch_array($result)){
$tot = $row['timedate'];
$ema = $row['email'];
$sendflag = $row['sent'];
$mess = $row['msgid'];
if(strtotime($tot) > time()) {
//echo "<tr><td>" .$row['timedate']."</td><td>";
echo"database dates higher then now dates" . "<br>";
echo "<tr><td>" .$row['email']."</td><td>" ."<br>";
echo "<tr><td>" .$row['timedate']."</td><td>" ."<br>";
echo "<tr><td>" .$row['sent']."</td><td>" ."<br>";
}
else {
echo"database dates lower then now dates" . "<br>";
echo "<tr><td>" .$row['email']."</td><td>". "<br>";
echo "<tr><td>" .$row['timedate']."</td><td>" ."<br>";
echo "<tr><td>" .$row['sent']."</td><td>" ."<br>";
$subject = "This is subject";
$message = "This is simple text message.";
$header = "From:abc#somedomain.com \r\n";
$to = $row['email'];
$retval = mail ($to,$subject,$message,$header);
if( $retval == true )
{
echo "Message sent successfully..." ."<br>";
}
else
{
echo "Message could not be sent..." ."<br>";
}
//$sql = "UPDATE mailer SET sent = 1 WHERE msgid = $mess";
$query = "UPDATE mailer SET sent = 1 WHERE msgid = $mess";
$result = mysql_query($query);
}
}
mysql_close();
?>
Rename the $result at the end to $result2 for example. You are overwriting the variable that you are looping.
I have a email script that runs every 15 minutes and is supposed to send a email once using PHP mailer. For some reason, it's sending out 3 emails a time.
Here's my code:
<?php
// Database connect
include("class.phpmailer.php");
$sql2 = "SELECT * FROM eblast_email WHERE id = '1'";
$result2 = mysql_query($sql2);
while ($myrow2 = mysql_fetch_array($result2)){
$get_event_id = "".$myrow2['event_id']."";
$mail = new PHPMailer();
// Login information here
$mail->Subject = "Subject here";
$html.= "HTML Message here";
$plain = "Plain Message here";
$mail->Body = $html;
$mail->AltBody = $plain;
$sql = "SELECT * FROM email_users WHERE sent = 'no' LIMIT 0, 40";
$result = mysql_query($sql);
while ($myrow = mysql_fetch_array($result)){
$email_to_send_to = "".$myrow['email']."";
$rsvp_check = mysql_query("SELECT * FROM event_members WHERE event_attending='$get_event_id' AND email='$email_to_send_to'");
$rsvp_check_done = mysql_num_rows($rsvp_check);
if ($rsvp_check_done == 0) {
$mail->AddAddress($email_to_send_to);
if(!$mail->Send()) {
echo "<b>Error sending email to " . $myrow['email'] . ". </b>" . $mail->ErrorInfo;
echo "<br>";
} else {
echo "Message to " . $myrow['email'] . " has been sent.<br>";
}
mysql_query("UPDATE email_users SET sent='yes' WHERE email='".$myrow['email']."'") or die (mysql_error());
$mail->ClearAddresses();
} else {
mysql_query("UPDATE email_users SET sent='yes' WHERE email='$email_to_send_to'") or die (mysql_error());
echo "$email_to_send_to has already registered ($rsvp_check_done) -- $get_event_id && $email_to_send_to<br>";
}
sleep(2);
}
}
echo "<br>Done.";
?>
Modify the code to have write to a log file every time it runs. My guess is that it's just getting called 3 times.
Example:
file_put_contents("log.txt", $_SERVER['REQUEST_TIME'] . "\n", FILE_APPEND);