我在网上发现了这个代码,它的作用就像一个魅力只有一件事......我也在尝试添加一个电话号码,但每次都收到错误。 ..我会想象,我只是将它添加到身体,但每次我尝试,它失败。即时通讯不确定我做错了什么。我相当新的PHP,所以如果有人可以向我解释为什么会发生这种情况,那将不胜感激。内容被保存到一个文件夹,但它似乎没有该文件夹被刷新一旦发送电子邮件...:\当我刷新我的页面时,我的电子邮件正在重新发送
<?php
$msg = "";
if (isset($_POST['submit'])) {
require 'phpmailer/PHPMailerAutoload.php';
function sendemail($to, $from, $fromName, $body, $attachment = "") {
$mail = new PHPMailer();
$mail->setFrom($from, $fromName);
$mail->addAddress($to);
$mail->addAttachment($attachment);
$mail->Subject = 'Contact Form - Email';
$mail->Body = $body;
$mail->isHTML(false);
return $mail->send();
}
$name = $_POST['username'];
$email = $_POST['email'];
$body = $_POST['body'];
$file = "attachment/" . basename($_FILES['attachment']['name']);
if (move_uploaded_file($_FILES['attachment']['tmp_name'], $file)) {
if (sendemail('[email protected]', $email, $name, $body, $file)) {
$msg = 'Email sent!';
} else
$msg = 'Email failed!';
} else
$msg = "Please check your attachment!";
}
?>
<html>
<head>
<title>Contact</title>
</head>
<style type="text/css">
input, textarea {
width:250px;
height: 27px;
margin-bottom: 10px;
}
textarea {
height: 200px;
width: 100%;
resize: vertical;
}
body {
text-align: center;
margin-top: 250px;
}
</style>
<body>
<img src="images/logo.png"><br><br>
<form method="post" action="index.php" enctype="multipart/form-data">
<input type="text" name="username" placeholder="Name..." required><br>
<input type="email" name="email" placeholder="Email..." required><br>
<textarea name="body" placeholder="Message..." required></textarea><br>
<input type="file" name="attachment" required><br>
<input type="submit" name="submit" value="Send Email">
</form>
<br><br>
<?php echo $msg; ?>
</body>
成功后,您需要重定向的页面。 –
提交表单后,如果通过刷新按钮或“F5”键刷新页面,表单将再次提交,因为该时间页面的提交值由您提交的表单提供。 – GYaN
问题标题与文中描述的内容之间的关系在哪里? – arkascha