2017-02-18 5 views
0

Ich versuche, eine Buchungsbestätigungs-E-Mail an den Kunden zu senden. Ich habe eine Bestätigungsvorlage mit HTML und CSS erstellt, wo einige Daten aus einem PHP-Formular generiert werden. Ich habe jetzt zwei Probleme. (1) Wenn ich die Vorlage erzeuge, und stattdessen die Vorlage zeigt, zeigt es nur die SUBMIT-Schaltfläche. (2) und ohne Klicken auf die Schaltfläche die Bestätigungsvorlage automatisch auf die Client-E-Mail mit dem Rohcode von HTML und CSS. Es zeigt die Vorlage in der E-Mail des Clients nicht an. Kann mir jemand helfen, das zu beheben? Beachten Sie, dass ich meinen gesamten HTML- und CSS-Code in einer PHP-Variable ($ message) aufbewahrt habe.Senden der Bestätigungsbriefvorlage an die E-Mail-Adresse des Kunden

<?php $message= '<!DOCTYPE html> 
<html> 
<head> </head> 
<body> 
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> 
<style type="text/css"> 
table { 
    width:100%; 
    } 
    table, th, td { 
     border: 2px solid #ffffff; 
     border-collapse: collapse; 
    } 
</style> 
<body> 

<div class="table">    
<table id="t01"> 
    <tr> 
    <td><?php echo $_POST["guestname"]; ?></td> 
    <td><?php echo $_POST["checkin"]; ?></td> 
    <td><?php echo $_POST["checkout"]; ?></td> 
    <td><?php echo $_POST["roomtype"]; ?></td> 
    <td><?php echo $_POST["rate"]; ?></td> 
    <td><?php echo $_POST["payment"]; ?></td> 
    <td><?php echo $_POST["resno"]; ?></td> 
</tr> 
</table> 
</div> <!-- table --> 
'; ?> 

<?php 
    $to = "[email protected]"; 
    $subject = "My subject"; 
    $txt = "$message"; 
    $headers = "From: [email protected]" . "\r\n" . 
    mail($to,$subject,$txt,$headers); 
?> 
<input type="submit" value="Send" /> 

Antwort

0

In Ihrem Senden Code benötigen Sie den Inhaltstyp der Mail angeben und als Header senden, zusätzlich müssen Sie Ihren PHP-Code ändern wie so

<?php 
$message = '<!DOCTYPE html> 
<html> 
    <head> 
     <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> 
     <style type="text/css"> 
      table { 
       width:100%; 
      } 
      table, th, td { 
       border: 2px solid #ffffff; 
       border-collapse: collapse; 
      } 
     </style> 
    </head> 
    <body> 
     <div class="table"> 
      <table id="t01"> 
       <tr> 
        <td>'.$_POST["guestname"].'</td> 
        <td>'.$_POST["checkin"].'</td> 
        <td>'.$_POST["checkout"].'</td> 
        <td>'.$_POST["roomtype"].'</td> 
        <td>'.$_POST["rate"].'</td> 
        <td>'.$_POST["payment"].'</td> 
        <td>'.$_POST["resno"].'</td> 
       </tr> 
      </table> 
     </div> <!-- table --> 
    </body> 
</html>'; 

//Set the headers and other mail data and mail it 
$to = '[email protected]'; 
$subject = 'My subject'; 

// To send HTML mail, the Content-type header must be set 
$headers[] = 'MIME-Version: 1.0'; 
$headers[] = 'Content-type: text/html; charset=iso-8859-1'; 

// Additional headers 
$headers[] = 'From: [email protected]'; 

// Mail it 
mail($to, $subject, $message, implode("\r\n", $headers)); 
?> 

Für weitere Referenz des documentation

+0

Dank lesen ... dieser Code funktioniert gut, aber ich ein anderes Problem konfrontiert bin, ist, dass, wenn diese Confirmat Die Seite wird generiert, die die Mail automatisch versendet. Ich möchte einen SEND-KNOPF verwenden, um dies an E-Mail zu senden. Wie kann ich das machen? –

+0

@AmiHasan mit HTML-Formulare wäre nett ' –

0

Ihr tr Tag wie diese Änderung

<tr> 
    <td>'.$_POST["guestname"].'</td> 
    <td>'.$_POST["checkin"].'</td> 
    <td>'.$_POST["checkout"].'</td> 
    <td>'.$_POST["roomtype"].'</td> 
    <td>'.$_POST["rate"].'</td> 
    <td>'.$_POST["payment"].'</td> 
    <td>'.$_POST["resno"].'</td> 
</tr> 

Sie mit php Tag innerhalb php Tag, das

0

entfernen <?php Code in <?php falsch ist. Auch setzt Inhaltstyp in Mail-Header

versuchen Sie dies:

<?php $message= '<!DOCTYPE html> 
<html> 
<head> </head> 
<body> 
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> 
<style type="text/css"> 
table { 
    width:100%; 
    } 
    table, th, td { 
     border: 2px solid #ffffff; 
     border-collapse: collapse; 
    } 
</style> 
<body> 

<div class="table">    
<table id="t01"> 
    <tr> 
    <td>'.$_POST["guestname"].'</td> 
    <td>'.$_POST["checkin"].'</td> 
    <td>'.$_POST["checkout"].'</td> 
    <td>'.$_POST["roomtype"].'</td> 
    <td>'.$_POST["rate"].'</td> 
    <td>'.$_POST["payment"].'</td> 
    <td>'.$_POST["resno"].'</td> 
</tr> 
</table> 
</div> <!-- table --> 
'; ?> 

<?php 
    $to = "[email protected]"; 
    $subject = "My subject"; 
    $txt = "$message"; 
    $headers = "From: [email protected]" . "\r\n" ; 
    mail($to,$subject,$txt,$headers); 

?> 
Verwandte Themen