这是剧本:
<?php
require_once 'swift-mailer/lib/swift_required.php';
$name = $_POST['name'];
$email = $_POST['email'];
$form_subject = $_POST['form_subject'];
$form_message = $_POST['form_message'];
if (isset($_POST['submit'])) {
if ($_POST['name'] != "") {
$_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
if ($_POST['name'] == "") {
$errors .= 'Please enter a valid name.<br/><br/>';
}
} else {
$errors .= 'Please enter your name.<br/>';
}
if ($_POST['email'] != "") {
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";
}
} else {
$errors .= 'Please enter your email address.<br/>';
}
if ($_POST['form_subject'] != "") {
$form_subject = filter_var($_POST['form_subject'], FILTER_SANITIZE_STRING);
if ($_POST['form_subject'] == "") {
$errors .= 'Please enter a valid subject.<br/><br/>';
}
} else {
$errors .= 'Please enter your subject.<br/>';
}
if ($_POST['form_message'] != "") {
$form_message = filter_var($_POST['form_message'], FILTER_SANITIZE_STRING);
if ($_POST['form_message'] == "") {
$errors .= 'Please enter a valid comment.<br/><br/>';
}
} else {
$errors .= 'Please enter your comment.<br/>';
}
if (!$errors) {
//File upload
// Where the file is going to be placed
$target_path = "uploads/";
// Add the original filename to our target path.
//Result is "uploads/filename.extension"
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
//End of file upload
//Create the Transport
$transport = Swift_MailTransport::newInstance();
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Create the message
$message = Swift_Message::newInstance();
//Give the message a subject
$message->setSubject('New data submitted');
$ip=$_SERVER['REMOTE_ADDR'];
$date=date("l, F j, Y, g:i a");
//Give it a body
$message->setBody("Here is the information submitted to
www.polycysticliverdisease.com/html/contact_email.php
from $ip on $date.\n\n
--------------------------------\n\n
name: $name \n\n
email address: $email \n\n
subject: $form_subject \n\n
comment: $form_message");
//Add alternative parts with addPart()
//$message->addPart('My amazing body in plain text', 'text/plain');
//Create the attachment
// * Note that you can technically leave the content-type parameter out
$attachment = Swift_Attachment::fromPath($target_path);
//Attach it to the message
$message->attach($attachment);
//Using setTo() to set all recipients in one go
$message->setTo(array('INFO@POLYCYSTICLIVERDISEASE.COM' => 'Diane Smith'));
//Set a From: address including a name
$message->setFrom(array('INFO@POLYCYSTICLIVERDISEASE.COM' => 'Contact Us'));
//Send the message
$numSent = $mailer->send($message);
//printf("Sent %d messages\n", $numSent);
if(isset($_FILES['uploadedfile'])){
$pathfile = "/home/vitusya/eximi.dreamhosters.com/Hawaii/html/uploads/" . $_FILES['uploadedfile']['name'];
@unlink($pathfile);
}
$to = "$email";
$subject = "Thank You!";
$body = "Thank you for e-mailing us. We will reply as soon as possible.";
mail($to, $subject, $body);
}
else {
echo '<div style="color: red">' . $errors . '<br/>
</div>';
}
}
?>
这是表格:
<form name="contact" action="contact_email.php" method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>
<h2 class="lower">Contact Us</h2>
</td>
</tr>
<tr>
<td class="pretty_border">
<label for="name">Your Name:</label><br />
<input class="text" type="text" name="name" />
<br />
</td>
</tr>
<tr>
<td class="pretty_border">
<label for="email">Your E-Mail Address:</label><br />
<input class="text" type="text" name="email" />
<br />
</td>
</tr>
<tr>
<td class="pretty_border">
<label for="form_subject">Subject:</label><br />
<input class="text" type="text" name="form_subject" />
<br />
</td>
</tr>
<tr>
<td class="textarea_border">
<label for="form_message">Your Message:</label><br />
<textarea rows="7" cols="50" name="form_message"></textarea>
<br />
</td>
</tr>
<tr>
<td>
<div class="fileinputs">
<input type="submit" class="file" name="submit" />
<div class="fakefile">
<img src="../assets/images/submit_btt.png" />
</div>
</div>
<div class="fileinputs">
<input type="file" class="file" name="uploadedfile" />
<div class="fakefile">
<img src="../assets/images/uf_btt.png" />
</div>
</div>
<div class="fileinputs">
<input type="reset" class="file" />
<div class="fakefile">
<img src="../assets/images/reset_btt.png" />
</div>
</div>
<div class="fileinputs">
<input type="button" class="file" onclick="window.print()" />
<div class="fakefile">
<img src="../assets/images/print_btt.png" />
</div>
</div>
</td>
</tr>
</table>
</form>
所有在Windows上使用任何浏览器都能正常工作,在iPhone和iPad上也能正常使用。 似乎问题出在Mac上。 脚本执行速度非常慢,并从错误的电子邮件地址向用户发送“谢谢”信。 此外,Mac上的谷歌浏览器似乎也有同样的问题。
您认为它可能是什么?
谢谢!
答案 0 :(得分:1)
执行时间与浏览器无关php是一种服务器端语言 您应该通过回显脚本中的各种变量来调试代码,并检查它们是否具有它们所假设的值,如果不是,您可能会查看之前回显变量的代码以查找可能出了什么问题