0

此表单将我的客户的订单数据插入到我的数据库中。如何使用http://php.net/manual/de/function.mail.php获取每个新订单以及格式清晰的纯文本电子邮件?我不知道如何处理它。

PHP 代码

<?php
$con = mysql_connect("localhost", "db_name", "password") or die ("Keine Verbindung zum MySQL-Server möglich"); 
mysql_select_db("db_name", $con) or die ("Keine Verbindung zur Datenbank möglich");
mysql_query("SET NAMES 'utf8'");

if (isset($_POST['button']))
{
foreach ($_POST AS $key => $postvar)
    $_POST[$key] = stripslashes($postvar);

$_POST['name'] = mysql_real_escape_string($_POST['name']);
$_POST['strasse'] = mysql_real_escape_string($_POST['strasse']);
$_POST['plz'] = mysql_real_escape_string($_POST['plz']);
$_POST['ort'] = mysql_real_escape_string($_POST['ort']);
$_POST['mail'] = mysql_real_escape_string($_POST['mail']);
$_POST['anzahl'] = mysql_real_escape_string($_POST['anzahl']);

$sql = "INSERT INTO `bestellungen` (`name`,`strasse`,`plz`,`ort`,`mail`,`anzahl`,`datetime`)
                VALUES ('".$_POST['name']."', '".$_POST['strasse']."', '".$_POST['plz']."', '".$_POST['ort']."', '".$_POST['mail']."', '".$_POST['anzahl']."', '".date("Y-m-d H:i:s")."');";

$result = mysql_query($sql,$con);
if (!$result) echo mysql_error();
mysql_close($con);
Header("Location: success.php");
exit();
?> 

HTML 代码

<form id="form" name="form" method="post" action="bestellung.php">

<span class="form_anzahl">Anzahl</span>
<select class="input_anzahl" name="anzahl"/>
<option>1</option>
<option>2</option>
</select><span class="form_artikel">Artikelname</span>

<span class="form_name">Name</span>
<input type="text" name="name" class="input_name" placeholder="Vor- und Nachname" required="required"/>

<span class="form_strasse">Straße</span>
<input type="text" name="strasse" class="input_strasse" placeholder="Straße und Hausnummer" required="required"/>

<span class="form_plz">PLZ</span>
<input pattern="[0-9]{5}" name="plz" class="input_plz" placeholder="12345" required="required"/>

<span class="form_ort">Ort</span>
<input type="text" name="ort" class="input_ort" placeholder="Ort" required="required"/>

<span class="form_mail">E-Mail</span>
<input type="email" name="mail" class="input_mail" placeholder="E-Mail" required="required"/>

<div id="redtxt_insert_bestellungen">Preis: 13,12 Euro</div><br>
<button type="submit" name="button" value="abschicken">bestellen</button>
<div class="spacer"></div>
</form>
4

1 回答 1

1

chnage 你foreach像这样循环:

$message='';
foreach ($_POST AS $key => $postvar):
    $_POST[$key] = stripslashes($postvar);
    $message.= "$key : $postvar \n";
    endforeach;

然后:

mail('me@example.com', 'New Order', $message);
于 2012-12-15T12:36:53.887 回答