email - PHP PDO send e-mail code only sends if text-only - need to send HTML -
i'm making code (1) moves records 1 table (in same database), (2) sends contents of table 1 pre-determined e-mail, , (3) delete contents of table 1 - simulating "add cart" feature.
my problem code below successful in sending e-mail if $headers not sent on mail(). however, need send table contents html or @ least allow
thanks in advance!
modified code (that works if don't send $headers
)
<?php include '../config/database.php'; date_default_timezone_set('cet'); $date = date('y-m-d h:i:s'); $query = "insert claims_archive (t20pctid, total_amount, user_id, sent) select t20pctid, total_amount, user_id, @date cart t20pctid '%sony%'"; $stmt = $con->prepare($query); if ($stmt->execute()) { $query = "select t.t20pctid, t.main_artist, t.track_title, t.original_album, c.total_amount cart c left join tblclaims t on t.t20pctid = c.t20pctid t.t20pctid '%sony%' order t.main_artist"; $stmt=$con->prepare($query); $stmt->execute(); $to = "testmail2@gmail.com"; $subject = "test"; $headers = "mime-version: 1.0" . "\r\n"; $headers .= "content-type:text/html;charset=utf-8" . "\r\n"; $headers .= "from: test <testmail1@mail.com>" . "\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 cart t20pctid '%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'; ?>
original code
<?php include '../config/database.php'; date_default_timezone_set('cet'); $date = date('y-m-d h:i:s'); $query = "insert claims_archive (t20pctid, total_amount, user_id, sent) select t20pctid, total_amount, user_id, @date cart t20pctid '%sony%'"; $stmt = $con->prepare($query); if ($stmt->execute()) { //header('location: cart.php?action=sent'); //please disregard line forgot remove when wrote post. $query = "select t.t20pctid, t.main_artist, t.track_title, t.original_album, c.total_amount cart c left join tblclaims t on t.t20pctid = c.t20pctid t.t20pctid '%sony%' order t.main_artist"; $stmt=$con->prepare($query); $stmt->execute(); $to = "testmail2@gmail.com"; $subject = "test"; $headers = "test <testmail1@mail.com>". "\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 cart t20pctid '%sony%'"; $stmt = $con->prepare($query_delete); $stmt->execute(); } else { header('location: cart.php?action=sent_failed'); } include 'layout_foot.php'; ?>
this
$success = mail($headers, $to, $subject, $body);
has not right parameter order ...
see http://php.net/manual/de/function.mail.php correct signature this:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
so
$success = mail($to, $subject, $body, $headers);
Comments
Post a Comment