我的联系表格.PHP没有给我发送任何详细信息,为什么?

w3nuxt5m  于 2023-03-07  发布在  PHP
关注(0)|答案(1)|浏览(115)

又来了,我找不到我的php代码有什么问题。当我收到一封邮件时,我只收到标题,没有从$_POST获得的信息,有人能帮助我吗?

HTML代码:

<div class="card card-style contact-form">
            <div class="content">
                <form action="/php/contact.php" method="post" class="contactForm" id="contactForm">
                    <fieldset>
                        <div class="form-field form-name">
                            <label class="contactNameField color-theme" for="contactNameField">Nome e Cognome*:<span>(*Campo obbligatorio)</span></label>
                            <input type="text" name="contactNameField" value="" class="round-small" id="contactNameField" />
                        </div>
                        <div class="form-field form-email">
                            <label class="contactEmailField color-theme" for="contactEmailField">Email*:<span>(*Campo obbligatorio)</span></label>
                            <input type="text" name="contactEmailField" value="" class="round-small" id="contactEmailField" />
                        </div>
                        <div class="form-field form-text">
                            <label class="contactMessageTextarea color-theme" for="contactMessageTextarea">Messaggio*: (Inserisci anche un tuo recapito telefonico oppure il tuo @ Telegram se preferisci essere ricontattato in questo modo)<span>(*Campo obbligatorio)</span></label>
                            <textarea name="contactMessageTextarea" class="round-small" id="contactMessageTextarea"></textarea>
                        </div>
                        <div class="form-button">
                            <input type="submit" class="btn bg-highlight text-uppercase font-900 btn-m btn-full rounded-sm  shadow-xl contactSubmitButton" value="INVIA MESSAGGIO" data-formId="contactForm" />
                        </div>
                    </fieldset>
                </form>
            </div>
        </div>

PHP代码:

<?php
    // variables start
    $name = "";
    $email = "";
    $message = "";
    
    $name =  trim($_POST['contactNameField']);
    $email =  trim($_POST['contactEmailField']);
    $message= trim($_POST['contactMessageTextarea']);
    // variables end
    
    // email address starts
    $emailAddress = 'supporto@mx-strength.it';
    // email address ends
    
    $subject = "MX-STRENGTH FORM: $name";   
    $message = "<strong>Inviato da:</strong> $name <br/><br/> <strong>Messaggio:</strong> $message";
    
    $headers .= 'From: '. $name . '<' . $email . '>' . "\r\n";
    $headers .= 'Reply-To: ' . $email . "\r\n";
    
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    //send email function starts
    mail($emailAddress, $subject, $message, $headers, $name);
    //send email function ends
?>

我的意思是,我在supporto@mx-strength.it上接收邮件,但我什么也看不到。这是我收件箱中接收内容的屏幕截图

jv4diomz

jv4diomz1#

请尝试以下PHP代码:

<?php
// no need for variables start  
$name =  htmlspecialchars($_POST['contactNameField']); //try replacing trim() with htmlspecialchars(). From personal experience, trim has sometimes given me false errors.
$email =  htmlspecialchars($_POST['contactEmailField']);
$message= htmlspecialchars($_POST['contactMessageTextarea']);
// variables end

// email address starts
$emailAddress = 'supporto@mx-strength.it';
// email address ends

$subject = "MX-STRENGTH FORM:". $name;   
$message = "<strong>Inviato da:</strong>". $name ."<br/><br/> <strong>Messaggio:</strong>". $message";

$headers .= 'From: '. $name . '<' . $email . '>' . "\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";

$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

//send email function starts
mail($emailAddress, $subject, $message, $headers, $name);
//send email function ends ?>

相关问题