dongyang7152 2018-05-02 14:53
浏览 107
已采纳

基本的php邮件问题:空白变量

I've got a strange problem: the same script is working in a different site I've built but not on my current one. The php script refers to a html page (a submitting form) and I just want to send it to an email. Here's the HTML code:

<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">

And here's the script:

    <?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);
}
?>

I receive the mail but it won't me display my variables! I don't know why and i'm getting crazy. The message is only "The following variables has been registered" followed by nothing at all..am I missing something in the syntax? In my old site is working fine.

Thank you all for your patience.

  • 写回答

1条回答 默认 最新

  • dongzhan7909 2018-05-02 15:09
    关注

    CodeCaster's comment is right, your form is making a request via the HTTP GET method - this is the default if you don't specify a method attribute on your form. But your PHP expects to find the variables in the $_POST array, which is only populated if the request is made using the HTTP POST method.

    The solution is very simple - tell your form what method to use:

    <form class="form-horizontal" action="invio_mail.php" method="POST">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败
  • ¥150 计算DC/DC变换器平均模型中的参数mu
  • ¥25 C语言代码,大家帮帮我
  • ¥15 请问以下文字内容及对应编码是用了什么加密算法或压缩算法呢?
  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错