我的php表单对我来说很好,但不知怎的,我收到了空白的电子邮件。我试图直接打开contact.php www.domain.com/php/contact.php就是这样。它发了一封空电子邮件。有人可以帮我阻止吗?
PHP
$mailTo = 'anfrage@domain.de';
$mailFrom = $_POST['email'];
$mailSubject = 'Kontakt';
$returnPage = 'versand_erfolgreich.php';
$returnErrorPage = 'versand_fehler.php';
$mailText = "";
if(isset($_POST["submit_button"])) {
foreach($_POST as $name => $value) {
if(is_array($value)) {
$mailText .= $name . ":\n";
foreach($valueArray as $entry) {
$mailText .= " " . $value . "\n";
} // ENDE: foreach
} // ENDE: if
else {
$mailText .= $name . ": " . $value . "\n";
} // ENDE: else
} // ENDE: foreach
} // if
if(get_magic_quotes_gpc()) {
$mailtext = stripslashes($mailtext);
}
$mailSent = @mail($mailTo, $mailSubject, $mailText, "From: ".$mailFrom);
if($mailSent == TRUE) {
header("Location: " . $returnPage);
}
else {
header("Location: " . $returnErrorPage);
}
exit();
HTML
<form class="form1" id="formular" role="form" action="php/kontakt.php" id="subscribeForm" method="POST">
<input class="inputsolo" type="text" name="Name" id="fname" placeholder="Name*" required="required">
<input class="inputsolo" type="text" name="email" id="email" placeholder="E-Mail Adresse*" required="required">
<input class="inputsolo" type="text" name="Telefon" id="phone" placeholder="0221 111 222*" required="required">
<input class="inputsolo" type="text" name="Betreff" id="betreff" placeholder="Betreff">
<input tabindex="-1" class="inputsolo betreff2" type="text" value="1" name="Betreff2" id="betreff2" placeholder="Betreff">
<input class="inputsolo paket" type="text" name="Ausgewählt:" id="web1" value="Webpaket Basis" readonly><img class="closewahl close1" src="css/images/close.png" alt="close"></img></input>
<input class="inputsolo paket" type="text" name="Ausgewählt:" id="web2" value="Webpaket Erweitert" readonly><img class="closewahl close2" src="css/images/close.png" alt="close"></img></input>
<input class="inputsolo paket" type="text" name="Ausgewählt:" id="web3" value="Webpaket Business" readonly><img class="closewahl close3" src="css/images/close.png" alt="close"></img></input>
<input class="inputsolo paket" type="text" name="Ausgewählt:" id="web4" value="Webpaket Universal" readonly><img class="closewahl close4" src="css/images/close.png" alt="close"></img></input>
<textarea class="inputpoly" name="message" placeholder="Ihre Nachricht.." id="message"></textarea>
<p id="fehler400"><u>ACHTUNG:<br>Es ist ein Fehler aufgetreten.</u><br><small>Verdacht auf Spam-Bot.</small><br>Bitte kontaktieren Sie uns per E-Mail oder telefonisch.<br><font style="font-family:arial,sans-serif;"><a href="tel:+32221212121" style="text-decoration:none;outline:none;color:#008aff;">+32221212121</a></font></p>
<input class="blue-btn" type="submit" id="send" value="Senden">
</form>
答案 0 :(得分:0)
您可能需要在提交按钮
中添加name="submit_button"
请注意即使您的$ _POST为空也发送电子邮件,因此您应将所有代码放入if(isset($_POST["submit_button"]))
块
答案 1 :(得分:0)
我不是PHP人,但我认为条件应该如下:
$mailTo = 'anfrage@domain.de';
$mailFrom = $_POST['email'];
$mailSubject = 'Kontakt';
$returnPage = 'versand_erfolgreich.php';
$returnErrorPage = 'versand_fehler.php';
$mailText = "";
if(isset($_POST["submit_button"])) {
foreach($_POST as $name => $value) {
if(is_array($value)) {
$mailText .= $name . ":\n";
foreach($valueArray as $entry) {
$mailText .= " " . $value . "\n";
} // ENDE: foreach
} // ENDE: if
else {
$mailText .= $name . ": " . $value . "\n";
} // ENDE: else
} // ENDE: foreach
if(get_magic_quotes_gpc()) {
$mailtext = stripslashes($mailtext);
}
$mailSent = @mail($mailTo, $mailSubject, $mailText, "From: ".$mailFrom);
if($mailSent == TRUE) {
header("Location: " . $returnPage);
}
else {
header("Location: " . $returnErrorPage);
}
} // if
exit();
答案 2 :(得分:0)
如果
,你应该把所有内容都包括在内 if(isset($_POST["submit_button"])) {
所以不要通过简单的访问发送电子邮件
答案 3 :(得分:0)
您的代码应该检查电子邮件中是否有任何值并且它不是空白,为此,您需要执行此操作
`
if(isset($_POST["submit_button"]) && $_POST['email']!='') {
$mailTo = 'anfrage@domain.de';
$mailFrom = $_POST['email'];
$mailSubject = 'Kontakt';
$returnPage = 'versand_erfolgreich.php';
$returnErrorPage = 'versand_fehler.php';
$mailText = "";
foreach($_POST as $name => $value) {
if(is_array($value)) {
$mailText .= $name . ":\n";
foreach($valueArray as $entry) {
$mailText .= " " . $value . "\n";
}
}
else {
$mailText .= $name . ": " . $value . "\n";
}
}
}else{
return false;
} if(get_magic_quotes_gpc()){
$mailtext = stripslashes($mailtext);
}
$mailSent = @mail($mailTo, $mailSubject, $mailText, "From: ".$mailFrom);
if($mailSent == TRUE) {
header("Location: " . $returnPage);
}
else {
header("Location: " . $returnErrorPage);
}
exit();
`
尝试用这个替换你。
答案 4 :(得分:0)
你的代码在粗略的注释上看起来很好,但你的邮件功能是在你的后置条件之外宣布的,所以当你打开你的联系我们页面时,它会给你错误,就像你打开那个页面一样(没有提交表格),然后你的数据变量没有设置,通过正常点击页面你正在调用mail函数,因为它没有包装在post check条件中,简单的修复是
<?php
if(isset($_POST["submit_button"])) {
$mailTo = 'anfrage@domain.de';
$mailFrom = $_POST['email'];
$mailSubject = 'Kontakt';
$returnPage = 'versand_erfolgreich.php';
$returnErrorPage = 'versand_fehler.php';
$mailText = "";
foreach($_POST as $name => $value) {
if(is_array($value)) {
$mailText .= $name . ":\n";
foreach($valueArray as $entry) {
$mailText .= " " . $value . "\n";
} // ENDE: foreach
} // ENDE: if
else {
$mailText .= $name . ": " . $value . "\n";
}
}
if(get_magic_quotes_gpc()) {
$mailtext = stripslashes($mailtext);
}
$mailSent = @mail($mailTo, $mailSubject, $mailText, "From: ".$mailFrom);
if($mailSent == TRUE) {
header("Location: " . $returnPage);
}
else {
header("Location: " . $returnErrorPage);
}
}
exit();
?>
此外,没有必要在检查后的情况下将这些变量声明为变量,因为您可能不需要它们,所以只有在您打算对它们做某些事情时才设置它们:)
同时检查您是否缺少提交按钮的名称属性(这非常关键),应该是:
<form class="form1" id="formular" role="form" action="php/kontakt.php" id="subscribeForm" method="POST">
<input class="inputsolo" type="text" name="Name" id="fname" placeholder="Name*" required="required">
<input class="inputsolo" type="text" name="email" id="email" placeholder="E-Mail Adresse*" required="required">
<input class="inputsolo" type="text" name="Telefon" id="phone" placeholder="0221 111 222*" required="required">
<input class="inputsolo" type="text" name="Betreff" id="betreff" placeholder="Betreff">
<input tabindex="-1" class="inputsolo betreff2" type="text" value="1" name="Betreff2" id="betreff2" placeholder="Betreff">
<input class="inputsolo paket" type="text" name="Ausgewählt:" id="web1" value="Webpaket Basis" readonly><img class="closewahl close1" src="css/images/close.png" alt="close"></img></input>
<input class="inputsolo paket" type="text" name="Ausgewählt:" id="web2" value="Webpaket Erweitert" readonly><img class="closewahl close2" src="css/images/close.png" alt="close"></img></input>
<input class="inputsolo paket" type="text" name="Ausgewählt:" id="web3" value="Webpaket Business" readonly><img class="closewahl close3" src="css/images/close.png" alt="close"></img></input>
<input class="inputsolo paket" type="text" name="Ausgewählt:" id="web4" value="Webpaket Universal" readonly><img class="closewahl close4" src="css/images/close.png" alt="close"></img></input>
<textarea class="inputpoly" name="message" placeholder="Ihre Nachricht.." id="message"></textarea>
<p id="fehler400"><u>ACHTUNG:<br>Es ist ein Fehler aufgetreten.</u><br><small>Verdacht auf Spam-Bot.</small><br>Bitte kontaktieren Sie uns per E-Mail oder telefonisch.<br><font style="font-family:arial,sans-serif;"><a href="tel:+32221212121" style="text-decoration:none;outline:none;color:#008aff;">+32221212121</a></font></p>
<input class="blue-btn" type="submit" id="send" value="Senden" name="submit_button">
</form>
快乐的编码。