2011-04-18 78 views
0

我正在編寫我的第一個PHP聯繫表格。我一整天都在努力。在Google上查找所有內容,我無法得到答案。從接觸轉到成功頁面,仍然沒有進入我的收件箱...........聯繫表格不發送電子郵件

PHP:

<?php 
    // Define some constants 
    define("RECIPIENT_NAME", "name"); 
    define("RECIPIENT_EMAIL", "[email protected]"); 
    define("EMAIL_SUBJECT", "Message"); 

    // Read the form values 
    $success = false; 
    $sender = isset($_POST['sender']) ? preg_replace("/[^\.\-\' a-zA-Z0-9]/", "", $_POST['sender']) : ""; 
    $email = isset($_POST['email']) ? preg_replace("/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email']) : ""; 
    $message = isset($_POST['message']) ? preg_replace("/(From: |To: |BCC: |CC: |Subject: |Content-Type:)/", "", $_POST['message']) : ""; 

    //If all values exist, send the email 
    if ($sender && $email && $message) { 
    $recipient = RECIPIENT_NAME . " <" . RECIPENT_EMAIL . $email . ">"; 
    $headers = "From: " . $sender . " <" . $email . ">"; 
    $success = mail($recipient, EMAIL_SUBJECT, $message, $headers); 
    } 

    // Return an appropriate reponse to the browser 
    if(isset($_GET["ajax"])) { 
    echo $success ? "success" : "error"; 
    } else { 
    ?> 
    <html> 
    <head> 
    <title>Thanks!</title> 
    </head> 
    <body> 
     <?php if ($success) echo "<h2>Thanks for sending your message! We'll get back to you shortly.</h2>" ?> 
     <?php if (!$success) echo "<h2> Sorry, There was a problem sending your message. Please try again.</h2>" ?> 
     <p> Click your browser's back button to return to the page</p> 
    </body> 
    </html> 
    <?php 
    } 
    ?> 

這有什麼錯呢?

繼承人的HTML

<form id="contactForm" action="process.php" method="post"> 
    <label for="sender">Your Name</label> 
    <input type="text" name="sender" id="sender" placeholder="Your Name" required="required" maxlength="40"> 

    <label for="email">Your Email Address</label> 
    <input type="email" name="email" id="email" placeholder="Please type your email address" 
    required="required" maxlength="50"> 

    <label for="message">Your Message</label> 
     <textarea name="message" id="message" placeholder="Please type your message" required="required" 
     cols="50" rows="5" maxlength="10000"></textarea>  

    <div id="form-buttons"> 
    <input type="submit" id="send-message" name="send-message" value="Send Email" /> 
    <input type="button" id="cancel" name="cancel" value="Cancel" /> 
    </div><!-- #form-buttons --> 

有人能來看看嗎?我敢肯定,我做的一切權利.....

回答

0

改變這一行:

$recipient = RECIPIENT_NAME . " <" . RECIPENT_EMAIL . $email . ">"; 

到:

$recipient = RECIPIENT_NAME . " <" . RECIPENT_EMAIL . ">"; 

,可能是這個問題

0

至少你行

$success mail($recipient, EMAIL_SUBJECT, $message, $headers); 

似乎是錯誤的,應該mail之前是一個等號。

+0

是啊,看起來像它。我很驚訝,這不是提出了一個錯誤 – wired00 2011-04-18 01:57:30

+0

好吧,我做了,仍然沒有。 – nowayyy 2011-04-18 02:05:38

相關問題