2017-04-05 34 views
-1

我幾年沒有編寫代碼,所以我要從5年前的項目中取消舊代碼,所以我不驚訝它不起作用;請給我一些關於如何使其工作的指示。電子郵件PHP表格不起作用

以下是我在我的HTML電子郵件的形式 -

<form action="fydcontact.php" method="post"> 

               <div class="form-group"> 
                <!--<label for="contact_name">Name:</label>--> 
                <input type="text" id="contact_name" class="form-control" placeholder="Name" /> 
               </div> 
               <div class="form-group"> 
                <!--<label for="contact_email">Email:</label>--> 
                <input type="text" id="contact_email" class="form-control" placeholder="Email Address" /> 
               </div> 
               <div class="form-group"> 
                <!--<label for="contact_message">Message:</label>--> 
                <textarea id="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea> 
               </div> 
               <button type="submit" class="btn btn-primary">Send</button> 

             </form> 

,這裏是我的PHP是什麼樣子 -

<?php 

if(isset($_POST['send'])) { 
    // Prepare the email 
$to = ''[email protected] '; 

$name = $_POST['contact_name']; 
$mail_from = $_POST['contact_email']; 
    $subject = 'Message sent from website'; 
    $message = $_POST['contact_message']; 

$header = "From: $name <$mail_from>"; 

    // Send it 
    $sent = mail($to, $subject, $message, $header); 
    if($sent) { 
    echo 'Your message has been sent successfully! <a href="http://www.foryourdayllc.com">Return to For Your Day, LLC Website</a>'; 
    } else { 
    echo 'Sorry, your message could not send. Please use direct email link on Contact Us page (below the map). <a href="http://www.foryourdayllc.com">Return to For Your Day, LLC Website</a>'; 
    } 
} 
?> 

任何幫助,不勝感激!謝謝!

+0

'$ to =''[email protected]';'那是一個錯誤;看看語法高亮。 –

+0

並且這個'if(isset($ _ POST ['send'])){...}'永遠不會觸發,並且你沒有名字屬性。 –

+0

非常感謝!我應該爲自己錯過那些非常簡單的事情而自責。然而,我很高興這只是那麼簡單,也許我在編碼方面沒有我想象的那麼生疏...再次,萬分感謝! – steamfunk

回答

0

更新

$to = ''[email protected] '; 

$to = '[email protected]'; 

,並需要添加name屬性的形式。此更新您的表格

<form action="fydcontact.php" method="post"> 

               <div class="form-group"> 
                <!--<label for="contact_name">Name:</label>--> 
                <input type="text" id="contact_name" name="contact_name" class="form-control" placeholder="Name" /> 
               </div> 
               <div class="form-group"> 
                <!--<label for="contact_email">Email:</label>--> 
                <input type="text" id="contact_email" name="contact_email" class="form-control" placeholder="Email Address" /> 
               </div> 
               <div class="form-group"> 
                <!--<label for="contact_message">Message:</label>--> 
                <textarea id="contact_message" name="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea> 
               </div> 
               <button type="submit" class="btn btn-primary" name ="send">Send</button> 

             </form> 
+0

非常感謝!我應該爲自己錯過那些非常簡單的事情而自責。然而,我很高興這只是那麼簡單,也許我在編碼方面沒有我想象的那麼生疏...再次,萬分感謝! – steamfunk