简体   繁体   中英

Can't send checklist to email from html

I need to do a simple script with two parts. First one is sending just name, phone number etc. and works perfectly already:

But after it i need to send a checklist to the same email, but still is nothing there.

My html:

 <form action="contact.php" method="post" id="form" class="contact-form"> <table style="color: DEB441; font-size: 19px; margin-left: 60px; margin-top: 40px; float: left;"> <tr> <td><font color="FFFFFF">Imie:</td> <td style="padding:0px"> <textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_imie" rows="2" cols="20"></textarea> </td> </tr> <tr> <td><font color="FFFFFF">Nazwisko:</td> <td style="padding:0px"> <textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_nazwisko" rows="2" cols="20"></textarea> </td> </tr> <tr> <td><font color="FFFFFF">Adres:</td> <td style="padding:0px"> <textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_adres" rows="2" cols="20"></textarea> </td> </tr> <tr> <td><font color="FFFFFF">Telefon</td> <td style="padding:0px"> <textarea style="outline-color: DEB441; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_telefon" rows="2" cols="20"></textarea> </td> </tr> <tr> <td><font color="FFFFFF">E-mail:</td> <td style="padding:0px"> <textarea style="outline-color: FFFFFF; margin-left: 23px; margin-bottom: 5px; overflow:auto;width:269px;height:15px;border:1px solid #DEB441;background:#fff;padding:3px 5px;color:#3D1E09;font:14px;font-style:italic;margin:0" name="cf_email" rows="2" cols="20"></textarea> </td> </tr> <tr> <td style="width: 150px;"> <p style="align: left; margin-top: 2px; margin-right: 10px;"><br> <font style="font-size: 16px;" color="#FFFFFF" align="left"> Wybierz produkty:<br><br> <font style="font-size: 12px;" color="#FFFFFF" align="left"> Herbatniki w pudelkach <br> <hr align="left" width="110px"><bt> <input type="checkbox" name="thenderese" value="thenderese" />Thenderese<br> <input type="checkbox" name="petipa" value="petipa" />Petipa<br> <input type="checkbox" name="biscripts" value="biscripts" />Biscripts<br> </p> </td> <td style="width: 150px;"> <p style="width: 250px; align: left;"><br> <font style="font-size: 12px;" color="#FFFFFF" align="left"> Herbatniki Pakowane pojedynczo<br> <hr align="left" width="160px"> <input type="checkbox" name="6g" value="g6g" />6g <input type="checkbox" name="150g" value="g150g" />150g <input type="checkbox" name="300g" value="g300g" />300g </p> </td> </tr> <tr> <td style="width: 200px; margin-right: 250px;"> <p align="left" style="align: left; margin-top:0px;"><br> <font style="font-size: 12px;" color="#FFFFFF" align="left"> Inne <hr align="left" width="150px"> <input type="checkbox" name="folia" value="folia">Biscripts opakowane w folie<br> <input type="checkbox" name="speculoos1" value="speculoos1" />1,5 kg (proszek speculoos)<br> <input type="checkbox" name="speculoos2" value="speculoos2" />1,1 kg (pokruszony speculoos)<br> <input type="checkbox" name="krem" value="krem biscripts" />krem biscripts<br> </p> </td> </tr> </table> </form> 

and my PHP

 <?php $field_imie = $_POST['cf_imie']; $field_nazwisko = $_POST['cf_nazwisko']; $field_adres = $_POST['cf_adres']; $field_telefon = $_POST['cf_telefon']; $field_email = $_POST['cf_email']; $field_message = $_POST['cf_message']; $mail_to = 'serwis@reskomp.pl'; $subject = 'nowe zamowienie '.$field_imie; $body_message = 'Od: '.$field_imie."\\n"; $body_message .= 'Nazwisko: '.$field_nazwisko."\\n"; $body_message .= 'Adres: '.$field_adres."\\n"; $body_message .= 'Telefon: '.$field_telefon."\\n"; $body_message .= 'Email: '.$field_email."\\n"; $body_message .= 'Szczegoly zamowienia: '.$field_message; $thenderese = $_POST['thenderese']; if ($thenderese != 'Yes') { $thenderese = 'No'; } $petipa = $_POST['petipa']; if ($petipa != 'Yes') { $petipa = 'No'; } $biscripts = $_POST['biscripts']; if ($biscripts != 'Yes') { $biscripts = 'No'; } $g6g = $_POST['6g']; if ($g6g != 'Yes') { $g6g = 'No'; } $g150g = $_POST['150g']; if ($g150g != 'Yes') { $g150g = 'No'; } $g300g = $_POST['300g']; if ($g300g != 'Yes') { $g300g = 'No'; } $folia = $_POST['folia']; if ($folia != 'Yes') { $folia = 'No'; } $speculoos1 = $_POST['speculoos1']; if ($speculoos1 != 'Yes') { $speculoos1 = 'No'; } $speculoos2 = $_POST['speculoos2']; if ($speculoos2 != 'Yes') { $speculoos2 = 'No'; } $krem = $_POST['krem']; if ($krem != 'Yes') { $krem = 'No'; } $headers = 'From: '.$field_email."\\r\\n"; $headers .= 'Reply-To: '.$field_email."\\r\\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Zamowienie zostalo przyjete do realizacji.'); window.location = '../herbatniki/index.html'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('Blad wysylania wiadomosci. Prosimy o kontakt na adres: coo.maan@gmail.com'); window.location = 'Contacts.html'; </script> <?php } ?> 

If somebody could help me... I know that i should use more css, but this is not the reason.

It looks like you have no way to submit your form.

Further, to add your checkbox data to your email message, you can use something like the following.

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
    var_dump($_POST);
    $message = '';
    $message .= sprintf("Name: %s\n", isset($_POST['name']) ? $_POST['name'] : '');
    $message .= sprintf("Foo wanted: %s\n", isset($_POST['foo']) ? 'Yes' : 'No');
    $message .= sprintf("Bar wanted: %s\n", isset($_POST['bar']) ? 'Yes' : 'No');
    var_dump($message);
}

?>

<form method="POST">
    Your Name:<input type="text" name="name" /><br />
    <input type="checkbox" name="foo" />You want Foo?<br />
    <input type="checkbox" name="bar" />You want Bar?<br />
    <input type="submit">
</form>

However please research 'email injection in php'.

You need to add the content to $body_message .

Change

$thenderese = $_POST['thenderese'];
if ($thenderese != 'Yes') {
    $thenderese = 'No';
}

to

$thenderese = $_POST['thenderese'];
$body_message .= 'thenderese';
if ($thenderese != 'Yes') {
    $body_message .= 'No';
}
else {
    $body_message .= 'Yes';
}
$body_message .= '/n';

and continue for the rest of your if statements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM