Hey Im目前正在为我的网站制作新闻通讯。我将用户数据存储在数据库中,并且具有有关该用户的以下信息:
所以我的问题是我不知道如何计算发送邮件的确切时间。我的第一个想法是将周期添加到用户订阅新闻通讯的日期,如果结果是当前日期,则发送新闻通讯。那有意义吗?
有人有想法吗?帮助将不胜感激!
这是我发送新闻简报的功能:
function sendNewsletter($userEmail, $username, $newsletterID)
{
include("../db_Data.php");
$dbMailSender = mysqli_connect($db_Data['server'], $db_Data['username'], $db_Data['password'], $db_Data['database']) or die("Datenbankverbindung gescheitert!");
$sql = "SELECT * FROM newsletter WHERE id = '$newsletterID'";
$newsletter = mysqli_query($dbMailSender, $sql) or die("Datenbankabfrage gescheitert!");
$newsletter = mysqli_fetch_assoc($newsletter);
$filePath = "../newsletters/";
$imgPath = "../uploads/";
$mail = new PHPMailer(true);
// Newsletter in objectBuffer laden, um Content der Datei in newsletterContent speichern zu können
ob_start();
include($filePath . $newsletter['htmlDatei']);
$newsletterContent = ob_get_contents();
ob_clean();
// SMTP Settings
$mail->Host = ""; // removed for security reasons
$mail->SMTPAuth = true;
$mail->Username = ""; // removed for security reasons
$mail->Password = ""; // removed for security reasons
$mail->SMTPSecure = "tls";
$mail->Port = 587;
// Mail Settings
$mail->addAddress($userEmail);
$mail->setFrom("newsletter@cankarka.com", "cankarka.com - Newsletter");
$mail->isHTML(true);
$mail->Subject = $newsletter['betreff'];
$mail->Body = $newsletterContent;
// Bilder für Newsletter laden
$mail->AddEmbeddedImage($imgPath . "logo.png", "logo");
$mail->AddEmbeddedImage($imgPath . "header.png", "header");
$mail->ADdEmbeddedImage($imgPath . "instagram.png", "instagram");
$mail->AddEmbeddedImage($imgPath . "youtube.png", "youtube");
$mail->AddEmbeddedImage($imgPath . "artstation.png", "artstation");
$mail->AddEmbeddedImage($imgPath . "sketchfab.png", "sketchfab");
$mail->AddEmbeddedImage($imgPath . "vorne.png", "3dChurch");
$mail->AddEmbeddedImage($imgPath . "He_Is_Damn_Close_Seq_canopy_Kamera_1.jpg", "dogfight");
$mail->AddembeddedImage($imgPath . "projectPreviewImage.jpg", "2dLogos");
$mail->AddembeddedImage($imgPath . "Agisoft_first_look.png", "agisoftScreenOne");
$mail->AddembeddedImage($imgPath . "Agisoft_second_look.png", "agisoftScreenTwo");
$mail->AddembeddedImage($imgPath . "Agisoft_final_look.png", "agisoftScreenThree");
$mail->AddembeddedImage($imgPath . "Cinema4D_look.png", "cinemaScreen");
// Email senden
if ($mail->send())
{
echo "<p>Sending Newsletter to $userEmail, the name is $username, the newsletterID is $newsletterID</p>";
$sql = "UPDATE newsletter SET used='true' WHERE id='$newsletterID'";
mysqli_query($dbMailSender, $sql) or die("Datenbankabfrage gescheitert!");
}
mysqli_close($dbMailSender);
}
在这里我想调用该函数(我的想法是遍历usertable并向每个用户发送新闻通讯):
$id = $_GET['id'];
include("../db_Data.php");
$db = mysqli_connect($db_Data['server'], $db_Data['username'], $db_Data['password'], $db_Data['database']) or die("Datenbankverbindung gescheitert!");
$sql = "SELECT * FROM member";
$users = mysqli_query($db, $sql) or die("Datenbankabfrage gescheitert!");
while ($row = mysqli_fetch_assoc($users))
{
$zeit = $row['datum_signed'];
$zeitraum = $row['zeitraum'];
$monateGone = date("m", time()) - date("m", $zeit);
$jahreGone = date("Y", time()) - date("Y", $zeit);
}
mysqli_close($db);