2017-04-05 33 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