2013-12-17 29 views
-2

嘿,我剛剛主持了我的第一個網站http://www.phillipparker.co.uk,但我的提交表單進入一個空白的網址http://www.phillipparker.co.uk/submit.php,但實際上並沒有發送HTML格式的詳細信息到指定的電子郵件。任何幫助將是巨大的apprecciated我的HTML表單代碼如下:通過PHP腳本發送HTML格式的詳細信息到一個電子郵件地址

<form name="form1" method="post" action="submit.php"> 
     <p> 
     <input name="Name" type="text" id="Name" size="30"> 
     </p> 
     <p> 
     <input name="Email" type="text" id="Email" size="30"> 
     </p> 
     <p> 
     <input name="Contact number" type="text" id="Contact number" size="30"> 
     </p> 
     <p> 
     <label> 
      <input type="radio" name="RadioGroupContact" value="Phone" id="RadioGroupContact_0"> 
      Phone</label> 
     <label> 
      <input type="radio" name="RadioGroupContact" value="Email" id="RadioGroupContact_1"> 
      Email</label> 
     </p> 
     <p> 
     <label> 
      <input type="radio" name="RadioGroupTime" value="Morning" id="RadioGroupTime_0"> 
      Morning</label> 
     <label> 
      <input type="radio" name="RadioGroupTime" value="Afternoon" id="RadioGroupTime_1"> 
     Afternoon</label> 
     <label> 
      <input type="radio" name="RadioGroupTime" value="Evening" id="RadioGroupTime_2"> 
     Evening</label> 
     <br> 
     </p> 
     <p> 
     <label for="Message"></label> 
     <textarea name="Message" id="Message" cols="30" rows="7"></textarea> 
     </p> 
     <p> 
     <input type="reset" name="Clear" id="Clear" value="Clear"> 
     <input name="Submit" type="submit" id="Submit" formaction="submit.php" formmethod="POST" value="Submit"> 
     </p> 
    </form> 
    </div> 
</div> 

我的PHP文件(submit.php)是如下:

<?php 
     if(isset($_POST['email'])) { 

    $email_to = "[email protected]"; 

    $email_subject = "www.phillipparker.co.uk"; 

    $Contact_number = $_POST[' Contact number ']; // required 

    $email_from = $_POST['Email']; // required 

    $Name = $_POST['Name']; // not required 

    $Message = $_POST['Message']; // required 

    $email_message = "Form details below.\n\n"; 


} 

    $email_message .= "Contact Number: ".clean_string($Contact_number)."\n"; 

    $email_message .= "Email: ".clean_string($email_from)."\n"; 

    $email_message .= "Name: ".clean_string($Name)."\n"; 

    $email_message .= "Message: ".clean_string($Message)."\n"; 

    $headers = 'From: '.$email_from."\r\n". 

    'Reply-To: '.$email_from."\r\n" . 

    'X-Mailer: PHP/' . phpversion(); 

    @mail($email_to, $email_subject, $email_message, $headers); 



    ?> 

我仍然在更新我的submit.php文件即包括過程單選按鈕,但我寧願得到c在我做任何改動之前,聯繫頁面工作。

在此先感謝

+0

什麼是對的 「clean_string」 功能?你可以發佈該代碼嗎? – DannyG

+0

你正在用'@'防止'mail'上的錯誤輸出。如果某件事失敗了,你就不會看到它。此外,你的submit.php不會產生任何HTML輸出;這就是爲什麼它是「空白」。你也可以考慮看看你的日誌。 'php.ini'可能被配置爲抑制你的錯誤並返回一個空白頁面。 – Julio

+1

在你的表單中,你已經調用了輸入'Email';你的PHP正在尋找'email'。 PHP區分大小寫。 – andrewsi

回答

1

您的PHP有點混亂。

<?php 
$emailTo = '<[email protected]>'; 
if($_SERVER['REQUEST_METHOD'] == 'POST') { 
$name = stripslashes(trim($_POST['form-name'])); 
$email = stripslashes(trim($_POST['form-email'])); 
$subject = stripslashes(trim($_POST['form-subject'])); 
$message = stripslashes(trim($_POST['form-message'])); 

$emailIsValid = preg_match('/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-  9_]+)*[.][A-z]{2,4}$/', $email); 

if($name && $email && $emailIsValid && $subject && $message){ 
    $subject = "[Contato via Site] $subject"; 
    $body = "Name: $name <br /> Email: $email <br /> Phone Number: $message <br /> Location: $subject"; 

    $headers = 'MIME-Version: 1.1' . PHP_EOL; 
    $headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL; 
    $headers .= "From: $name <$email>" . PHP_EOL; 
    $headers .= "Return-Path: $emailTo" . PHP_EOL; 
    $headers .= "Reply-To: $email" . PHP_EOL; 

    mail($emailTo, $subject, $body, $headers); 
    $emailSent = true; 
} else { 
    $hasError = true; 
} 
} 
?> 

使用此的頭部將這個對錶單本身和需求自訂你請。

<?php if(isset($emailSent) && $emailSent): ?> 
    <div class="col-md-6 col-md-offset-3"> 
     <div class="alert alert-success text-center">Thank You! An ADT representative will contact you shortly.</div> 
    </div> 
<?php else: ?> 
    <?php if(isset($hasError) && $hasError): ?> 
    <div class="col-md-5 col-md-offset-4"> 
     <div class="alert alert-danger text-center">Hmmm... It seems there was an error, please try again and make sure all the fields are filled out.</div> 
    </div> 
    <?php endif; ?> 

<div class="col-md-6 col-md-offset-3"> 
    <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" id="contact-form" class="form-horizontal" role="form" method="post" style="height: 300px; padding-left:10px; padding-top:10px;"> 

    <label for="name" style="font-size:20px; padding-top: 5px; padding-bottom: 5px;">Full Name</label> 

       <input type="text" id="form-name" name="form-name" placeholder="John Smith" /> 


      <label for="email" style="font-size:20px; padding-top: 5px; padding-bottom: 5px;" >Email</label> 

       <input type="email" id="form-email" name="form-email" placeholder="[email protected]" /> 

      <label for="mensagem" style="font-size:20px; padding-top: 5px; padding-bottom: 5px;">Phone Number</label> 

       <input type="text" id="form-message" name="form-message" placeholder="555-234-8765" /> 

       <label for="assunto" style="font-size:20px; padding-top: 5px; padding-bottom: 5px;">City and State</label> 

       <input type="text" id="form-subject" name="form-subject" placeholder="Los Angeles, CA" /> 
     <p style="font-size: 7px;">By clicking "Call Me" I agree to the <a href="terms.html">Terms and Conditions</a></p> 


       <div class="modal-footer"> 
<button type="sumbit" name="submit" value="Submit" class="btn btn-primary">Call Me</button> 

+0

在doctype html之前將頂級代碼放在頭部。 – 2013-12-17 20:05:45

相關問題