我的頁面不保留在同一頁面我在這裏有點新。我試圖自己創建我的網站,雖然已經快完成了,但我無法解決以我的聯繫表單發送信息的問題。當我點擊選項提交
頁是這樣的:ramproducciones.pe(這是在西班牙) 如果他們對他們發現的接觸形式走到底,即使他們正確填寫數據時,發送電子郵件,但接下來的事情是一個空白給出頁面。我想要的是你收到一條消息說,謝謝你!您的消息已發送,但我不知道如何操作。我試圖複製許多代碼和我目前有此:
<!-- contacto-->
<section class="contact" id="contact">
<h1>Contacto</h1>
<hr/>
<div class="content">
<div class="form">
<form method="post" action="mail.php" name="contact">
<div class="column">NOMBRE<br/><br/>
<input name="name" id="name" value="" />
</div>
<div class="column-2">E-MAIL<br/><br/>
<input name="email" id="email" value="" />
</div>
<div class="column-3">MENSAJE<br/><br/>
<textarea id="message" name="message" ></textarea>
</div>
<div class="button">
<span><input class="submit" id="submit" name="submit" type="submit" value="ENVIAR"></span>
</div>
<div id="dialog-message" title="Thank You">
<p>¡Gracias! Tu mensaje ha sido enviado, te responderemos lo antes posible.</p>
</div>
</form>
</div>
<div class="contact-text">
No dudes en solicitarnos información.<br/><br/>
<strong>RAM Producciones</strong><br/><br/>
e-mail: <strong>[email protected]</strong>
<br/><br/>
<a href="https://facebook.com/RAMproduccionesSAC" target="_blank"><img src=img/social/Facebook.png /></a>
<a href="https://vimeo.com/ramproduccionessac" target="_blank"><img src=img/social/Vimeo.png /></a>
<a href="https://www.behance.net/RAMProduccionesSAC" target="_blank"><img src=img/social/Behance.png /></a>
<a href="https://www.instagram.com/ram.producciones" target="_blank"><img src=img/social/Instagram.png /></a>
<a href="https://www.youtube.com/channel/UCIF9shcqE4D5cF5Xp7LBasg" target="_blank"><img src=img/social/Youtube.png /></a>
</div>
</div>
</section>
的,而PHP是
<?php
// define variables and set to empty values
$name_error = $email_error = "";
$name = $email = $message = $success = "";
//form is submitted with POST method
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$name_error = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$name_error = "Solo ingresa letras y espacios.";
}
}
if (empty($_POST["email"])) {
$email_error = "Tu E-mail es necesario";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email_error = "Formato de E-mail inválido";
}
}
if (empty($_POST["message"])) {
$message = "";
} else {
$message = test_input($_POST["message"]);
}
if ($name_error == '' and $email_error == '' and $phone_error == '' and $url_error == ''){
$message_body = '';
unset($_POST['submit']);
foreach ($_POST as $key => $value){
$message_body .= "$key: $value\n";
}
$to = '[email protected]';
$subject = 'Mail vía RAMPRODUCCIONES.PE';
if (mail($to, $subject, $message)){
$success = "¡Gracias! Tu mensaje ha sido enviado, te responderemos lo antes posible.";
$name = $email = $message = '';
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
不過我還是解決不了問題。
這是你的行爲。 – clearshot66
它去mail.php文件。 –
當表單被提交時,您可以將它們發送到另一個頁面,在您的表單標籤中帶有這個'action =「mail.php」'。另外,值得注意的是'test_input()'函數大多是無用的,只是破壞了數據而不是提供「安全性」。 – Qirel