2015-09-07 2 views
1

Я спутать с использованием одинарных и двойных кавычек, эхом, и $ сообщения. =Как закодировать цикл Еогеаспа в почтовом сообщении

Я не могу понять, как кодировать цикл Еогеаспа внутри моих $ сообщений на выводит элементы корзины. Эта часть работает, но область тела дефектна. Любая помощь приветствуется.

<?php 
session_start(); 
// Initialize variables 
$name = $telephone = $email = $jim_gmail = ''; 

// Post data from @quote-form.html.php 
if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { 

// Sanitize and post data to variables 
$company = sanitize($_POST['company']); 
$name = sanitize($_POST['name']); 
$telephone = sanitize($_POST['telephone']); 
$email = sanitize($_POST['email']); 

// Assign $name value to SESSION variable for use @thankyou.html.php 
$_SESSION['name'] = $name; 

// Initialize and declare variables for script validation 
$errMsg = ''; 
$telephone_pattern = '/^((([0-9]{1})*[- .(]*([0-9]{3})[- .)]*[0-9]{3}[- .]*[0-9]{4})+)*$/'; 
$alpha_only_pattern = '/^[a-zA-Z]*$/'; 
$email_pattern = '/^([a-zA-Z0-9._%-][email protected][a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$/'; 
$integers_pattern = '/^[0-9]*$/'; 

// Validate user data before submitting to server 
if(empty($name) || empty($telephone) || empty($email)) 
{ 
    $errMsg = "*Name, telephone and email address required.<br>"; 
    include 'error.html.php'; 

} 
elseif (preg_match($email_pattern,$email) === 0) 
{ 
    $errMsg = "*Please enter a valid email address.<br>"; 
    include 'error.html.php'; 

} 
else 
{ 

/* Prepare message for e-mail */ 
/* set e-mail recipient */ 

$jim_gmail = '[email protected]'; 


// Three required arguments ($to, $subject, $message) 
$to = "$jim_gmail"; 
$subject = "Buyer for CraneHeli"; 
$from = "$email"; 
$message = // contents of report in $message 
" 
<html> 
<head></head> 
<body> 
    <h3>Parts Buyer</h3> 
    <p>Company: $company</p> 
    <p>Name: $name</p> 
    <p>Telephone: $telephone</p> 
    <p>Email: $email</p> 
    <h3>Please quote the following:</h3>  
    <table name='contact_seller' style='border-collapse:collapse';> 
     <thead> 
      <tr> 
       <th>ID</th> 
       <th>Part Number</th> 
       <th>Description</th> 
       <th>Quantity</th> 
      </tr>  
     </thead> 
     <tbody> 
      <?php foreach($cart as $item): ?> 
      <tr> 
       <td>$item['id']</td> 
       <td>$item['part_number']</td> 
       <td>$item['description']</td> 
       <td>$item['quantity']</td> 
      </tr> 
      <?php endforeach; ?> 
     </tbody> 
    </table> 
    <p>End of buyer data report</p> 
    <hr />  
</body> 
</html> 
"; //end of $message 

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n";  // code to send HTML on UNIX 
$headers .= 'Content-type:text/html; charset=iso-8859-1' . "\r\n"; 

// Additional headers 
$headers .= 'From: ' . $from . "\r\n"; 
$headers .= 'Bcc: ' . $jim_gmail . "\r\n";  // works 
$headers .= 'Bcc: ' . $jim_gmail . "\r\n";  // works 

    // Send message using mail() function 
    mail($to, $subject, $message, $headers); 

    // Check to see if headers not sent. If true, redirect to thank_you.php page 
    if(!headers_sent()){ 
     header('Location: thankyou.html.php'); 
     exit(); 
    }else{ 
     echo "<span class='errMsg'>Message sent successfully!</span><br><br>" . 
      "Cannot redirect, please click this <a " . 
      "href=\".\">link</a> instead\n"; 
    } 
    exit();   
} 

/******* Functions used *******/ 
    function sanitize($data) { 
     $data = trim($data); 
     $data = stripslashes($data); 
     $data = htmlspecialchars($data); 
     return $data; 
    } 
+0

вы делаете это неправильно, 1. 'близко«; ',' 2. $ temp = ''; foreach ($ cart as $ item) {$ temp. = " {$ item ['id']} {$ item ['part_number']} {$ item ['description']} {$ item ['quantity']} "; } ', 3. после этого' $ message. = $ Temp. «

Конец данных покупателя сообщить


„“' – anonymous

ответ

1

Ты почти там:

$message = // contents of report in $message 
     " 
     <html> 
     <head></head> 
     <body> 
      <h3>Parts Buyer</h3> 
      <p>Company: $company</p> 
      <p>Name: $name</p> 
      <p>Telephone: $telephone</p> 
      <p>Email: $email</p> 
      <h3>Please quote the following:</h3>  
      <table name='contact_seller' style='border-collapse:collapse';> 
       <thead> 
        <tr> 
         <th>ID</th> 
         <th>Part Number</th> 
         <th>Description</th> 
         <th>Quantity</th> 
        </tr>  
       </thead> 
       <tbody>"; 
        foreach($cart as $item) { 
         $message .="<tr> 
          <td>" . $item['id'] ."</td> 
          <td>".$item['part_number']."</td> 
          <td>".$item['description']."</td> 
          <td>".$item['quantity']."</td> 
         </tr>"; 
        } 
       $message .= "</tbody> 
      </table> 
      <p>End of buyer data report</p> 
      <hr />  
     </body> 
     </html>"; //end of $message 

Примите к сведению конкретно:

<tbody>"; 
        foreach($cart as $item) { 
         $message .="<tr> 
          <td>" . $item['id'] ."</td> 
          <td>".$item['part_number']."</td> 
          <td>".$item['description']."</td> 
          <td>".$item['quantity']."</td> 
         </tr>"; 
        } 
       $message .= "</tbody> 
      </table> 
+0

Спасибо @Amo за две вещи: (1) вашего скорейшего экспертного ответа, и (2) за поддержку в высказывании»Ты почти там. «Теперь я изучу ваше решение, чтобы понять, как это. Спасибо, что нашли время, чтобы помочь мне. – JimB814

Смежные вопросы