2017-01-22 7 views
0

Ich muss Formulardaten an Mail im Tabellenformat senden. Dafür benutze ich PHPMailer. Wenn ich versuche, Werte anzuzeigen, die vom Benutzer ausgewählt wurden, wird es nur als Array angezeigt. Kann mir jemand helfen, herauszufinden, was in diesem Code falsch ist?Senden von Formulardaten an Mail mit PHP-Mailer nicht möglich

Unten ist der Teil von HTML

<input type="checkbox" name="Favorite_Drink[]" value="Vodka">Vodka 
<input type="checkbox" name="Favorite_Drink[]" value="Vodka">Vodka 
<input type="checkbox" name="Favorite_Drink[]" value="Bear">Bear 

Hier PHP Teil ist

$Favorite_Drink = $_POST['Favorite_Drink']; 
$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        // Enable verbose debug output 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = 'pass';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 

$mail->setFrom('[email protected]', 'User'); 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
//$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
//$mail->addBCC('[email protected]'); 
$mail->Subject = 'Here is the subject'; 
//$mail->Body = "Name of patient is "; 
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 
$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true); 
$mail->Subject = ' Test'; 
$mail->Body = <<<EOF 
<html><body> 

    <br> 
    <table rules="all" style="border-color: #666;" cellpadding="10"> 
     <tr style='background: #eee;'> 
      <td>Favorite_Drink </td> 
      <td> $Favorite_Drink</td> 
     </tr> 
</table> 
</body> 
</html> 
EOF; 

      //Altbody is used to display plain text message for those email viewers which are not HTML compatible 

$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 
     } 
} 

Antwort

1

$Favorite_Drink = $_POST['Favorite_Drink']; - diese Variable bekommt Array von Daten aus Form. <td> $Favorite_Drink</td> - Wenn Sie Array als Text drucken möchten, sollten Sie etwas implode verwenden (',', $ Favorite_Drink)

+0

Entschuldigung..es funktioniert nicht! – phpLover

+0

Diese Antwort ist richtig - Sie können ein Array nicht direkt drucken, Sie müssen jedes seiner Elemente verarbeiten. Ich denke, phpLover muss etwas härter sein ... – Synchro

Verwandte Themen