Salve a tutti,ho da poco terminato la realizzazione in html/css del mio primo sito e,da buon novellino di php,mi sono incagliato sul form contatti;Per testare il sito sto usando xampp mentre, per l'invio di mail, ho provato con uno script.php presente in un template di bootstrap che ho usato come scheletro per costruire il sito;Succede che appena clicco invia dal form contatti, anziché spedire la mail,si apre una pagina web con lo script php usato.
Vi posto lo script incriminato:
<?php
// check for form submission - if it doesn't exist then send back to contact form
if (!isset($_POST['save']) || $_POST['save'] != 'contact') {
header('Location: contact1.html'); exit;
}
// get the posted data
$name = $_POST['contact_name'];
$email_address = $_POST['contact_email'];
$phone = $_POST['contact_phone'];
$message = $_POST['contact_message'];
// check that a name was entered
if (empty($name))
$error = 'You must enter your name.';
// check that an email address was entered
elseif (empty($email_address))
$error = 'You must enter your email address.';
// check for a valid email address
elseif (!preg_match('/^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$/', $email_address))
$error = 'You must enter a valid email address.';
// check that a phone number was entered
if (empty($phone))
$error = 'You must enter your phone number.';
// check that a message was entered
elseif (empty($message))
$error = 'You must enter a message.';
// check if an error was found - if there was, send the user back to the form
if (isset($error)) {
header('Location: contact1.html?e='.urlencode($error)); exit;
}
$headers = "From: $email_address\r\n";
$headers .= "Reply-To: $email_address\r\n";
// write the email content
$email_content = "Name: $name\n";
$email_content .= "Email Address: $email_address\n";
$email_content .= "Phone Number: $phone\n";
$email_content .= "Message:\n\n$message";
// send the email
//ENTER YOUR INFORMATION BELOW FOR THE FORM TO WORK!
mail ('[email protected]', 'YOUR WEBSITE NAME - contact-form-submission1', $email_content, $headers);
// send the user back to the form
header('Location: contact1.html?s='.urlencode('Thank you for your message.')); exit;
?>
Quali sono gli errori?Dove sbaglio?
Grazie a chiunque voglia aiutarmi!Ciao