我想用PHP郵件()函數發送電子郵件。它發送電子郵件,但只有HTML部分,不包括通過PHP的動態值。任何幫助將不勝感激。PHP的郵件功能只發送HTML不採摘PHP數據
我想使它工作,但它不工作。我嘗試了多種變體,但它仍然只發送HTML部分。
$to = $vendor_email;
$subject = "";
$mime_boundary = '<<<--==+X['.md5(time()).']';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-Type: multipart/mixed;';
$headers[] = ' boundary="'.$mime_boundary.'"';
$message = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/home.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<title>BuyBusTours</title>
<style>
body{
font-family: Calibri,Candara,Segoe,"Segoe UI",Optima,Arial,sans-serif;
}
h4{
text-align: center;
}
#wrapper{
width: 60%;
}
hr{
border-color: black;
border-width: 1px;
}
label{
display: inline-block;
width: 250px;
}
</style>
</head>
<body>
<div class="container" id="wrapper">
<h3 style="text-align: center; background-color: orange; height: 60px; padding-top: 18px;">Booking Confirmation for Order Number: { <?php echo $order_id;?> }</h3>
<h4>Dear <?php echo $vendor_name ?></h4><br>
<h4>Thank you for Choosing BuyBusTours</h4>
<hr>
<p style="color:red;">This is the confirmation email that we have received your order and it is processing. Please do not confuse it with your e-ticket.</p>
<p>We have received your order and we are working on it. As soon as your order is confirmed we will send your E-Ticket. Complete information about your tour and other important details will be mentioned on your E-Ticket. If in case your tour is sold out or it is not operating we shall refund your complete payment.
</p>
<p>This is <b>NOT A CONFIRMATION</b> that you have reserved a seat on the bus. We are working on your order and as soon as it is confirmed we will send your e-ticket.</p>
<hr>
<h3 style="color:#F60">Order Details</h3>
<label>Tour Name:</label><?php echo $tour_name;?><br>
<label>Departure Date</label> <?php echo $dept_date;?> <br>
<label>Departure Location:</label> <?php echo $dept_loc;?> <br>
<label>Tour Code:</label> <?php echo $tourcode;?> <br>
<label>Vendor Tour Code:</label> <?php echo $vendorcode;?> <br>
<label>Number of People:</label> <?php echo $no_of_adult + $no_of_child;?> <br>
<?php if (!empty($no_of_rooms)) { ?>
<?php for ($i = 1 ; $i <= $no_of_rooms ; $i++) {?>
<?php if ($i == 1) {?>
<label style="color:#F33">Room <?php echo $i;?></label> <br>
<?php if (!empty($room1traveler1)) {?>
<label>Traveler 1: </label>
<?php echo $room1traveler1;?><br>
<?php } ?>
<?php if (!empty($room1traveler2)) {?>
<label>Traveler 2: </label>
<?php echo $room1traveler2;?><br>
<?php } ?>
<?php if (!empty($room1traveler3)) {?>
<label>Traveler 3: </label>
<?php echo $room1traveler3;?><br>
<?php } ?>
<?php } ?>
<?php if ($i == 2) {?>
<label style="color:#F33">Room <?php echo $i;?></label><br>
<?php if (!empty($room2traveler1)) {?>
<label>Traveler 1: </label>
<?php echo $room2traveler1;?><br>
<?php } ?>
<?php if (!empty($room2traveler2)) {?>
<label>Traveler 2: </label>
<?php echo $room2traveler2;?><br>
<?php } ?>
<?php if (!empty($room2traveler3)) {?>
<label>Traveler 3: </label>
<?php echo $room2traveler3;?><br>
<?php } ?>
<?php } ?>
<?php if ($i == 3) {?>
<label style="color:#F33">Room <?php echo $i;?></label><br>
<?php if (!empty($room3traveler1)) {?>
<label>Traveler 1: </label>
<?php echo $room3traveler1;?><br>
<?php } ?>
<?php if (!empty($room3traveler2)) {?>
<label>Traveler 2: </label>
<?php echo $room3traveler2;?><br>
<?php } ?>
<?php if (!empty($room3traveler3)) {?>
<label>Traveler 3: </label>
<?php $row["room3_traveler3"];?><br>
<?php } ?>
<?php } ?>
<?php if ($i == 4) {?>
<label style="color:#F33">Room <?php echo $i;?></label><br>
<?php if (!empty($room4traveler1)) {?>
<label>Traveler 1: </label>
<?php echo $room4traveler1;?><br>
<?php } ?>
<?php if (!empty($room4traveler2)) {?>
<label>Traveler 2: </label>
<?php echo $room4traveler2;?><br>
<?php } ?>
<?php if (!empty($room4traveler3)) {?>
<label>Traveler 3: </label>
<?php echo $room4traveler3;?><br>
<?php } ?>
<?php } ?>
<?php } }?>
<hr>
<h3 style="color:red; text-align:center">Total Amount Charged: <?php echo $total_price;?></h3>
<h3 style="text-align: center; background-color: orange; height: 60px; padding-top: 18px;">Contact us at: 0345-1272211</h3>
</div>
</body>
</html>';
$message = html_entity_decode($message);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
由於'$ message'是一個變量'$ message ='<',所以您需要將php變量稍微不同。您可以使用「點」(例如'打斷引號和連接。 $ tourcode。 '
然後你回到文本html直到下一個變量。你不需要'echo'。一個更大的例子http://stackoverflow.com/questions/33965765/get-variable-in-while-loop-based-on-what-user-chooses/33966051#33966051你還需要From:和Reply-To:values in您的標題和電子郵件必須來自服務器上的有效地址。 – Steve