簡體   English   中英

PHP HTML 聯系表

[英]PHP HTML Contact Form

我在網站上有一個聯系表格,該表格使用 php 腳本將詳細信息發送到我的電子郵件。

我遇到的問題是名字字段中的數據根本沒有發送到我的電子郵件。

我有一種感覺,這將是一個非常明顯的錯誤,但我似乎無法找到錯誤!

PHP

<?php 
    $ToEmail = 'myemail@mycompany.com'; 
    $EmailSubject = 'BGM Contact Form'; 
    $mailheader = "From: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
    $MESSAGE_BODY = "First Name: ".$_POST["firstName"].""; 
    $MESSAGE_BODY = "Last Name: ".$_POST["lastName"].""; 
    $MESSAGE_BODY .= "Email: ".$_POST["email"].""; 
    $MESSAGE_BODY .= "Comment: ".nl2br($_POST["message"]).""; 
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?>

HTML

<form action="thankyou.php"  onsubmit="return validateForm();" method="post">
    <div class="row collapse">
        <div class="large-2 columns">
            <label class="inline">First Name</label>
        </div>
        <div class="large-10 columns">
            <input type="text" id="firstName" name="firstName" placeholder="Jane" required>
        </div>
    </div>

    <div class="row collapse">
        <div class="large-2 columns">
            <label class="inline">Last Name</label>
        </div>
        <div class="large-10 columns">
            <input type="text" id="lastName" name="lastName" placeholder="Smith" required>
        </div>
    </div>

    <div class="row collapse">
        <div class="large-2 columns">
            <label class="inline" > Your Email</label>
        </div>
        <div class="large-10 columns">
            <input type="text" name="email" id="yourEmail" placeholder="jane@smithco.com" required>
        </div>
    </div>
    <label>Your Message</label>
    <textarea rows="8" name="message" required></textarea>
    <br><br>
    <button type="submit" class="radius button">Submit</button>
</form>

錯誤在這里

$MESSAGE_BODY = "First Name: ".$_POST["firstName"].""; 
$MESSAGE_BODY = "Last Name: ".$_POST["lastName"]."";

將其更改為

$MESSAGE_BODY = "First Name: ".$_POST["firstName"].""; 
$MESSAGE_BODY .= "Last Name: ".$_POST["lastName"].""; 

您正在覆蓋包含 firstName 的第一個 $MESSAGE_BODY

通過將".替換為單引號"嘗試以下操作

<?php 
    $MESSAGE_BODY .= "First Name: '$_POST["firstName"]'"; 
    $MESSAGE_BODY .= "Last Name: '$_POST["lastName"]'"; 
    $MESSAGE_BODY .= "Email: '$_POST["email"]'"; 
    $MESSAGE_BODY .= "Comment: 'nl2br($_POST["message"])'"; 
?>

你的 php 腳本有問題

$ToEmail = 'myemail@mycompany.com'; 
        $EmailSubject = 'BGM Contact Form'; 
        $mailheader = "From: ".$_POST["email"]."\r\n"; 
        $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
        $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
        $MESSAGE_BODY = "First Name: ".$_POST["firstName"].""; 
        $MESSAGE_BODY .= "Last Name: ".$_POST["lastName"].""; 
        $MESSAGE_BODY .= "Email: ".$_POST["email"].""; 
        $MESSAGE_BODY .= "Comment: ".nl2br($_POST["message"]).""; 
        mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

使用上面的php腳本

我在使用php腳本的網站上有聯系表,將詳細信息發送到我的電子郵件中。

我遇到的問題是,“名字”字段中的數據根本沒有發送到我的電子郵件中。

我感覺這將是一個非常明顯的錯誤,但是我似乎找不到該錯誤!

的PHP

<?php 
    $ToEmail = 'myemail@mycompany.com'; 
    $EmailSubject = 'BGM Contact Form'; 
    $mailheader = "From: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
    $MESSAGE_BODY = "First Name: ".$_POST["firstName"].""; 
    $MESSAGE_BODY = "Last Name: ".$_POST["lastName"].""; 
    $MESSAGE_BODY .= "Email: ".$_POST["email"].""; 
    $MESSAGE_BODY .= "Comment: ".nl2br($_POST["message"]).""; 
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?>

的HTML

<form action="thankyou.php"  onsubmit="return validateForm();" method="post">
    <div class="row collapse">
        <div class="large-2 columns">
            <label class="inline">First Name</label>
        </div>
        <div class="large-10 columns">
            <input type="text" id="firstName" name="firstName" placeholder="Jane" required>
        </div>
    </div>

    <div class="row collapse">
        <div class="large-2 columns">
            <label class="inline">Last Name</label>
        </div>
        <div class="large-10 columns">
            <input type="text" id="lastName" name="lastName" placeholder="Smith" required>
        </div>
    </div>

    <div class="row collapse">
        <div class="large-2 columns">
            <label class="inline" > Your Email</label>
        </div>
        <div class="large-10 columns">
            <input type="text" name="email" id="yourEmail" placeholder="jane@smithco.com" required>
        </div>
    </div>
    <label>Your Message</label>
    <textarea rows="8" name="message" required></textarea>
    <br><br>
    <button type="submit" class="radius button">Submit</button>
</form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM