邮件功能php无法正常工作

时间:2015-12-31 15:23:31

标签: php email

因此,我建立了一个网站,人们可以通过表格将其包含在他们想要参加的活动中。

他们的想法是填写表格

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="lettertype">
<p>Voeg een nieuwe inschrijving toe:</p><br>
<label for = "Naam">Naam: </label><input type="text" name="Naam" class="naam"/><br />
<label for = "Klas">Klas: </label><input type="text" name="Klas" class="klas"/><br />
<label for = "Email">E-mail: </label><input type="text" name="Email" class="e-mail"/><br />
<label for = "Bericht">Opmerking: </label><input type="text" name="Bericht" class="bericht" rows="7" cols="40"/><br />

<input type="submit" value="Verstuur" class="submit"/><br />
</form>

在他们填写表格后,该表格中的数据将存储在数据库中。哪个实际上正在工作...但....另一个想法是,他们也会收到一封电子邮件,告诉他们订阅是以正确的方式完成的,并且他们在de数据库中。我有点失去了现在要做的事情,我的代码如下:

唯一不起作用的是邮件,我不知道为什么。

    <?php

error_reporting(0); // disable errors
// VOOR DEZE OPDRACHT MOET AUTO-INCREMENT AAN STAAN!
if ($_SERVER["REQUEST_METHOD"] == "POST")
{ 

    $naam = htmlspecialchars($_POST['Naam']);
    $klas = htmlspecialchars($_POST['Klas']);
    $email = htmlspecialchars($_POST['Email']);
    $bericht = htmlspecialchars($_POST['Bericht']);



$servername = "149.210.209.156";
$username = "mar_info_inschri";
$password = "buigbZUWXoU4";
$dbname = "marklandloop_info_inschri";

    error_reporting(E_ERROR | E_PARSE);

    $conn = mysqli_connect($servername, $username, $password, $dbname);

    if (mysqli_connect_errno()) {
        printf("<p><b>Fout: verbinding met de database mislukt (is MySQL actief?).</b><br/>\n%s</p>\n", 
                    mysqli_connect_error());
        exit();
    }

    $sql = "INSERT INTO leerling(Naam, Klas, Email, Bericht) VALUES ( '" .$naam. "', '" .$klas. "' , '" .$email. "', '" .$bericht. "');" ;



    $result = mysqli_query($conn, $sql) or die(mysql_error($conn));
    if ($result === false) {
        echo "Niet gelukt";
    }else{
        "<div> class='tekstformulier'>" . echo "Je inschrijving is verzonden" . "</div>";}







$tijd = time();
$datum = strftime('%d/%m/%y %H:%M', $tijd);
$ip = getenv('REMOTE_ADDR');
$subject = "Inschrijfformulier (Marklandloop) - $naam";
$message =
'U hebt zich iingeschreven voor de Marklandloop met de volgende gegevens:

Naam: '.$naam.'
Klas: '.$klas.'
E-mail: '.$email.'
Dit bericht werd verstuurd op: '.$datum.'.
____________________________________
Opmerkingen:

'.$bericht.'
------------------------------------';

mail('$email', $subject, $message, 'From: ', $naam);

require_once "path/to/adodb.inc.php";
error_reporting(E_ALL);



    // maak de resultset leeg
    mysqli_free_result($results);

    // sluit de connection
    mysqli_close($conn);
}

?>

1 个答案:

答案 0 :(得分:0)

这对我来说并不合适:

        }else{
    "<div> class='tekstformulier'>" . echo "Je inschrijving is verzonden" . "</div>";}

如果您尝试将邮件功能替换为:

,会发生什么
    mail($email, $subject, $message, 'From: '.$naam);