我遇到了一个奇怪的问题:同一个脚本在我建立的不同网站上工作但在我当前的网站上却没有。 php脚本引用了html页面(提交表单),我只是想将其发送到电子邮件。这是HTML代码:
<form class="form-horizontal" action="invio_mail.php">
<div class="form-group">
<label for="indirizzo">Indirizzo attivazione</label>
<input id="indirizzo" name="indirizzo" type="text" class="form-control" placeholder="Via Roma, 15" required autofocus>
</div>
<div class="form-group">
<label for="modem">Tipo di modem</label>
<select id="modem" name="modem" class="form-control">
<option>Indoor</option>
<option>Outdoor</option>
</select>
</div>
....
<input name="submit" class="btn btn-lg btn-primary btn-block" type="submit" value="Invia">
以下是剧本:
<?php
$mailto = 'myemail@gmail.com';
$subject = 'Form';
$error_message = 'Wooops! Something goes wrong.';
$success_message = '<strong><em>SENT!</em></strong>';
$indirizzo = $_POST['indirizzo'];
$modem = $_POST['modem'];
$consegna = $_POST['consegna'];
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$dob = $_POST['dob'];
$paese = $_POST['paese'];
$citta = $_POST['citta'];
$codice_fiscale = $_POST['codice_fiscale'];
$cellulare = $_POST['cellulare'];
$documento = $_POST['documento'];
$scadenza_doc = $_POST['scadenza_doc'];
$rilascio_doc = $_POST['rilascio_doc'];
$email = $_POST['email'];
$note = $_POST['note'];
$message = "The following variables has been registered: $indirizzo $modem $consegna $nome $cognome $dob $paese $citta $codice_fiscale $cellulare $documento $scadenza_doc $rilascio_doc $email $note";
$headers = "Da: " . "X-Mailer: PHP/" . phpversion();
if (mail($mailto, $subject, $message, $headers)) {
echo("<br>$success_message <br><br><br>");
;
} else {
echo($error_message);
}
?>
我收到了邮件,但它不会显示我的变量!我不知道为什么,我变得疯狂。 消息仅为&#34;以下变量已注册&#34;什么都没有......我在语法中遗漏了什么? 在我的旧网站工作正常。
感谢大家的耐心等待。
答案 0 :(得分:0)
CodeCaster的评论是正确的,您的表单是通过HTTP GET
方法发出请求的 - 如果您未在表单上指定method
属性,则这是默认设置。但是你的PHP希望在$ _POST数组中找到变量,只有在使用HTTP POST
方法发出请求时才会填充该变量。
解决方案非常简单 - 告诉您的表单使用哪种方法:
<form class="form-horizontal" action="invio_mail.php" method="POST">