I know there are plenty of questions regarding this topic on stackoverflow, but none of the answers have been very helpful for me. I'm trying to make a contact form for a website were the user would input their name, email, and a message, and then an email would be sent to the owner of the website using PHP's mail() function. I'm using a XAMPP server to run the PHP file. This is my html:
<form action="http://localhost/website/php/contact.php" method="post">
<p>Your Name</p>
<input class="input-field" type="text" name="cf_name">
<p>Your e-mail</p>
<input class="input-field" type="text" name="cf_email">
<p>Message</p>
<textarea class="text-field" name="cf_message"></textarea>
<input id="contact-send" class="form-button" type="submit" value="Send">
</form>
and this is my PHP:
<?php
$name = $_POST["cf_name"];
$email = $_POST["cf_email"];
$message = $_POST["cf_message"];
$from = $name;
$to = "email@domain.com";
$subject = "Thanks for getting ahold of us!";
$body = "From: ".$name."\r\n";
$body = "E-mail: ".$email."\r\n";
$body = "Message:\r\n".$message;
if (mail($to, $subject, $body, $from)){
echo '<p>Your message has been sent!</p>';
}else{
echo '<p>Something went wrong</p>';
}
?>
It always prints out the "something went wrong" line. Could my XAMPP server set up wrong? I'm quite lost right now.
Aucun commentaire:
Enregistrer un commentaire