来自PHP电子邮件脚本的意外空白页面

时间:2013-12-19 14:54:17

标签: php sql email date format

好的我已经重新设计了它并不完美,但它可以在网址中进行测试并通过cronjobs进行测试。

<html>
<head>
<title>J~Net Birthday Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body style="background:#0066CC">
<font color="orange" font size="+1">
<center>

<?php
error_reporting(E_ALL); ini_set('display_errors', "0");
$id = '';
$email = '';
$numrows = '';
function sendHTMLemail($HTML,$from,$to,$subject) {
$from = "admin@jnetscripts.com";
$subject = "Happy Birthday ";
$headers = "From: $from\r\n";
$HTML = '
<body style="background:#0066CC">
<STYLE TYPE="text/css">
BODY {background-image: url(\'http://www.jnetscripts.com/apps/balance/images/images(9).jpeg\');
background-repeat; }
</STYLE> 
<font color="orange" font size="+1"><center>
<a href="http://www.jnetscripts.com"><img src="http://www.jnetscripts.com/images/logo.png" height="80px" ></img></a>
<p><br>
<p>
Happy Birthday To You!<p> 
Happy Birthday To You!<p>
Happy Birthday To You!<p>
Happy Birthday To You!<p>
<p><br>
Have A Great Day From J~Net<p>
<a href="http://www.jnetscripts.com"><img src="http://www.jnetscripts.com/images/logo.png" height="80px" ></img></a>';
$headers .= "MIME-Version: 1.0\r\n";
$boundary = uniqid("HTMLEMAIL");
$headers .= "Content-Type: multipart/alternative;".
"boundary = $boundary\r\n\r\n";
$headers .= "This is a MIME encoded message.\r\n\r\n";
$headers .= "--$boundary\r\n".
"Content-Type: text/plain; charset=ISO-8859-1\r\n".
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode(strip_tags($HTML)));
// Now we attach the HTML version
$headers .= "--$boundary\r\n".
"Content-Type: text/html; charset=ISO-8859-1\r\n".
"Content-Transfer-Encoding: base64\r\n\r\n";
$headers .= chunk_split(base64_encode($HTML));
if (mail($to,$subject,"",$headers)) {
global $success;
$success++;
}
}
$now = date("d-m-y");
$out  = array('-');
$in = array('');
$new_now = str_replace($out, $in, $now);
$new_now = substr($new_now, 0, 4);
echo 'Todays Date Without The Year Is ';
echo $new_now;
echo '<p>';
require_once("../php_includes/db_conx.php");
$sql = "SELECT id, username, email, dob FROM users WHERE instr(dob, '$new_now') >0";
$query = mysqli_query($db_conx, $sql);
if($query){
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$id = $row['id'];
$email = $row['email'];
$username = $row['username'];
}
if (sendHTMLemail($HTML,$from,$email,$subject)) {
echo 'No Birthdays today!';
} else {
echo 'Messages Sent';
}
}
?>
</head>
<body>
</body>
</html>

我发布此信息是为了帮助其他人,他们可能希望在英国英语格式的数据库中格式化日期(正确方法)。 很快,我可以回答我自己的问题(需要更多代表),请投票,所以我没有编辑原始部分!

1 个答案:

答案 0 :(得分:0)

获得$new_now变量的方式真是太神奇了。你添加破折号,然后你用一个键创建数组,然后用虚线替换破折号。只需使用$now = date("dmy");,你就完成了。

现在我不知道您对数据库中DOB列使用的存储类型。但如果它datedatetime不起作用。如果它是varchar那么它可以工作。我想知道为什么如果要检查同一个表中的列,你会使用FIND_IN_SET。如果它是一个varchar,你可以使用WHERE dob='".$new_now."'

如果列类型为DATE仍然可以使用,但您应将$new_now更改为date("Y-m-d")date("Y-m-d H:i:s") DATETIME(尽管日期时间是如果生日存储在09:03且脚本运行在12:48,则会出现问题

更新:

再次阅读,我错过了$new_now = substr($new_now, 0, 4);部分。你只是检查月/日(显然)。因此,如果dob字段是varchar,那么您可以使用

$new_now = date("dm"); //day and month, both with leading 0
"SELECT username, email, dob FROM users WHERE dob LIKE '".$new_now."%'";