0

I'm trying to make a simple contact page, but everytime I try to send a message, I get an error.

Here is the PHP code:

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "mailto:benten@benniestudios.eu";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $email, $formcontent, $mailheader) or die("Error!");
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
echo '<a href="http://www.benniestudios.eu">Return Home</a>';
?> 

What did I do wrong? If you need more info, please tell me.

KIKO Software
  • 15,283
  • 3
  • 18
  • 33
Bennie
  • 1
  • 1
  • 2
    It would be informative if you mentioned what exact error you get. – KIKO Software Nov 06 '21 at 14:04
  • The `mailto:` in the `$recipient` is normally used in a HTML link, but probably shouldn't be used here in PHP. – KIKO Software Nov 06 '21 at 14:09
  • I don't know what the problem is. I get 'Error!', because of this piece of code: `or die("Error!")`. It doesn't give me any other kind of error, but I don't recieve any message. Also, I've tried it without `mailto:` and that won't work either. – Bennie Nov 06 '21 at 14:10
  • This is the link to the contact form, if it helps: [benniestudios.eu/contact](https://benniestudios.eu/contact/) – Bennie Nov 06 '21 at 14:13
  • For real error reporting see: [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display?rq=1). – KIKO Software Nov 06 '21 at 14:15
  • I found the problem. I removed $subject from the `mail()` function and now it works. Is there a way so I can keep subject? – Bennie Nov 06 '21 at 14:50
  • Why not read the manual: [mail()](https://www.php.net/manual/en/function.mail.php) – KIKO Software Nov 06 '21 at 14:59

0 Answers0