嘿,我刚刚托管了我的第一个网站http://www.phillipparker.co.uk,但我的提交表单转到了一个空白网址http://www.phillipparker.co.uk/submit.php,但实际上并没有将html表单详细信息发送到指定的电子邮件。任何帮助都会非常感激我的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 = "4001@gmail.com";
$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文件,包括单选按钮,但我希望在进行任何更改之前让联系页面正常工作。
提前致谢
答案 0 :(得分:1)
你的PHP有点乱。
在
之前把它放在头脑中 <?php
$emailTo = '<YOUR@EMAIL.COM>';
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="example@yourdomain.com" />
<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>