gpt4 book ai didi

php - 用 PHP 和 MySql 发送电子邮件

转载 作者:行者123 更新时间:2023-11-29 12:20:02 24 4
gpt4 key购买 nike

您好,我正在尝试使用 while 循环从数据库获取数据来发送电子邮件。电子邮件功能正常,但电子邮件中仅附加一条记录。如何发送所有记录。我的代码如下。

    $selectorder=$con->query("select * from products , order_details where order_details.order_id='$order_id' AND products.product_id=order_details.product_id");
while($fetch_order_details=$selectorder->fetch_array())
{
$product_detail_id=$fetch_order_details['product_id'];
$product_detail_unit=$fetch_order_details['unit_price'];
$product_detail_sub=$fetch_order_details['sub_price'];
$product_detail_qty=$fetch_order_details['quanitity'];
$total;
$pname=$fetch_order_details['product_title'];
$strMessage = "
<tr>
<td>Item Name</td>
<td>Item Price</td>
<td>Item Quanitity</td>
<td>Item Sub Price</td>
<td>Item Total Price</td>
</tr>
<tr>
<td>$pname;</td>
<td>$product_detail_unit;</td>
<td> $product_detail_qty;</td>
<td> $product_detail_sub;</td>
<td>$total;</td>
</tr>";
}


$subject = "Your Order Number" .$order_id;
$message="$strMessage";
$header="From:<xxx@gmail.com>";
$to="$customeremail";
$send=mail($to,$subject,$message,$header);
if($send)
{
echo "send successfully";
}
else
{
echo "not successfully";
}
}

}

最佳答案

更改以下行

Line 0: 
Line 1: $selectorder=$con->query("select * from products , order_details where order_details.order_id='$order_id' AND products.product_id=order_details.product_id");

Line 0: $strMessage = "";
Line 1: $selectorder=$con->query("select * from products , order_details where order_details.order_id='$order_id' AND products.product_id=order_details.product_id");

并且

Line 10:   $strMessage = '

Line 10: $strMessage.= '

这会将字符串附加到变量,而不是每次都覆盖该值。

    $strMessage = "";

$selectorder=$con->query("select * from products , order_details where order_details.order_id='$order_id' AND products.product_id=order_details.product_id");

while($fetch_order_details=$selectorder->fetch_array())
{
$product_detail_id=$fetch_order_details['product_id'];
$product_detail_unit=$fetch_order_details['unit_price'];
$product_detail_sub=$fetch_order_details['sub_price'];
$product_detail_qty=$fetch_order_details['quanitity'];

$total; //Why is this in here?

$pname=$fetch_order_details['product_title'];

$strMessage.= "
<tr>
<td>Item Name</td>
<td>Item Price</td>
<td>Item Quanitity</td>
<td>Item Sub Price</td>
<td>Item Total Price</td>
</tr>
<tr>
<td>$pname;</td>
<td>$product_detail_unit;</td>
<td> $product_detail_qty;</td>
<td> $product_detail_sub;</td>
<td>$total;</td>
</tr>";
}


$subject = "Your Order Number" .$order_id;
$message="$strMessage";
$header="From:<xxx@gmail.com>";
$to="$customeremail";
$send=mail($to,$subject,$message,$header);
if($send)
{
echo "send successfully";
}
else
{
echo "failed";
}

关于php - 用 PHP 和 MySql 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29159464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com