duanao4503
2019-05-22 19:51
浏览 47
已采纳

PHP MAIL:我的一个变量发送“false”值

I am sending an e-mail with different variables as an JSON encoded array from an online store. I get the mail just fine and all the data is in there except for one of the variables, which is a JSON encoded array by itself. this particular variable shows as "false" in the e-mail. I'm missing something?

I'm using PHP mail to do it.

<?php
require_once "Mail.php";

$link = mysqli_connect("localhost", "xxx", "xxx", "xxx");

if ($link === false) {
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

$sql = "SELECT * FROM users WHERE user = '" . $_SESSION['logged'] . "'";
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_assoc($result);

$user = $_SESSION['logged'];
$rua = $_POST['rua'];
$numero = $_POST['numero'];
$apt = $_POST['apt'];
$cep = $_POST['cep'];
$total = $_POST['total'];
$comment = $_POST['observacion'];
$from = $row['mail'];
$mailTo = "xxxxx@hotmail.com";
$subject = "compra online - no cep";

$compra = $_SESSION["shopping_cart"];
$compra2 = json_encode($compra);

$bod = array(
    'user' => $user,
    'rua' => $rua,
    'cep' => $cep,
    'compra' => $compra2,
    'comment' => $comment,
    'total' => $total,
);

$body = json_encode($bod);

$headers = array(
    'From' => $from,
    'To' => $mailTo,
    'Subject' => $subject,
);

$smtp = Mail::factory('smtp', array(
    'host' => 'smtp-mail.outlook.com',
    'port' => '587',
    'auth' => true,
    'username' => 'xxxxxxx@hotmail.com',
    'password' => 'xxxxxxx',
));

$mail = $smtp->send($mailTo, $headers, $body);

if (PEAR::isError($mail)) {
    echo ("<p>" . $mail->getMessage() . "</p>");
} else {
    header("Location: lojacart.php?mailok");
}

mysqli_close($link);

I'm getting the e-mail with all the data except for the $compra2 variable which is showing as 'compra'=false. now if I echo the variable $compra2 it actually have a large string of data on it.

I think it might have to do with the variable being a JSON encoded session, but I'm not sure.

1条回答 默认 最新

相关推荐 更多相似问题