Ich mache diesen Code, der (1) Datensätze von einer Tabelle in eine andere verschiebt (in der gleichen Datenbank), (2) sendet Inhalt von Tabelle 1 zu einer vorgegebenen E-Mail, und (3) löschen Sie den Inhalt von Tabelle 1 - Simulation einer "Add to Cart" -Funktion.PHP PDO senden E-Mail-Code sendet nur wenn nur Text - HTML senden müssen
Mein Problem ist, dass der folgende Code nur erfolgreich beim Senden der E-Mail ist, wenn $ Headers nicht auf Mail() gesendet wird. Allerdings muss ich den Tabelleninhalt als HTML senden oder zumindest
Vielen Dank im Voraus!
Modified-Code (das funktioniert, wenn ich nicht $headers
senden DO)
<?php
include '../config/database.php';
date_default_timezone_set('CET');
$date = date('Y-m-d H:i:s');
$query = "INSERT INTO claims_archive (t20pctID, total_amount, user_id, sent) SELECT t20pctID, total_amount, user_id, @date FROM cart WHERE t20pctID LIKE '%sony%'";
$stmt = $con->prepare($query);
if ($stmt->execute()) {
$query = "SELECT t.t20pctID, t.main_artist, t.track_title, t.original_album, c.total_amount FROM cart c LEFT JOIN tblclaims t ON t.t20pctID = c.t20pctID WHERE t.t20pctID LIKE '%sony%' ORDER BY t.main_artist";
$stmt=$con->prepare($query);
$stmt->execute();
$to = "[email protected]";
$subject = "Test";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: Test <[email protected]>" . "\r\n";
$body = "Sent on: ". $date . "-\r\n";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
$body .= "Track title: ".$row ["track_title"]. "-";
}
$success = mail($headers, $to, $subject, $body);
if ($success) {
$query_delete = "DELETE FROM cart WHERE t20pctID LIKE '%sony%'";
$stmt = $con->prepare($query_delete);
$stmt->execute();
header('Location: cart.php?action=sent');
} else {
header('Location: cart.php?action=sent_failed');
}
} else {
header('Location: cart.php?action=sent_failed');
}
include 'layout_foot.php';
?>
<?php
include '../config/database.php';
date_default_timezone_set('CET');
$date = date('Y-m-d H:i:s');
$query = "INSERT INTO claims_archive (t20pctID, total_amount, user_id, sent) SELECT t20pctID, total_amount, user_id, @date FROM cart WHERE t20pctID LIKE '%sony%'";
$stmt = $con->prepare($query);
if ($stmt->execute()) {
//header('Location: cart.php?action=sent'); //please disregard this line as I forgot to remove it when I wrote this post.
$query = "SELECT t.t20pctID, t.main_artist, t.track_title, t.original_album, c.total_amount FROM cart c LEFT JOIN tblclaims t ON t.t20pctID = c.t20pctID WHERE t.t20pctID LIKE '%sony%' ORDER BY t.main_artist";
$stmt=$con->prepare($query);
$stmt->execute();
$to = "[email protected]";
$subject = "Test";
$headers = "Test <[email protected]>". "\r\n". "MIME-Version: 1.0" ."\r\n". "Content-type: text/html; charset=iso-8859-1" ."\r\n";
$body = "Sent on: ". $date . "-";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
$body .= "Track title: ".$row ["track_title"]. "-";
}
$success = mail($to, $subject, $body);
if ($success) {
header('Location: cart.php?action=sent');
} else {
header('Location: cart.php?action=sent_failed');
}
$query_delete = "DELETE FROM cart WHERE t20pctID LIKE '%sony%'";
$stmt = $con->prepare($query_delete);
$stmt->execute();
} else {
header('Location: cart.php?action=sent_failed');
}
include 'layout_foot.php';
?>
Ihre Umleiten vor E-Mail zu senden - Ihr Kopf Gebrauch machen keinen Sinn –
Hallo Dagon. Danke, dass du darauf hingewiesen hast. Ich habe vergessen, die erste Weiterleitung zu entfernen. Das Problem tritt immer noch auf. – Hola