0
Hi everyone, could anyone give me an idea of what's wrong with this PHP of a contact form? I get a 500 error when running it.
<?php $name = $_POST['firstname']; $email = $_POST['email']; $jobtype = $_POST['jobtype']; $message = $_POST['message']; $formcontent" From: $name \n Type of Job: $jobtype \n Message: $message"; $recipient = "*********@gmail.com" $subject = "Website Contact Form Message"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank you!"; ?>
5 odpowiedzi
+ 4
//Maybe you are trying to send mail from local server , there are other steps to that + you have some error on concat string and variables
+ 1
It's been a while since I touched PHP but I am excited to see that it's still rather garbage.
The mail function does different things on windows and linux; in either case you need to dive into your php.ini file.
If you are on windows, you need to find the `SMTP` and `smtp_port` options and set them accordingly.
(Mail is sent via the smtp protocol. You can set up an smtp server on your machine, but other mailservers won't trust you and mails will be marked as spam. It's better to use gmail smtp servers or whatever)
Also try this, to get better error messages:
(Taken from the php.net user comments)
<?php
$success = mail('example@example.com', 'My Subject', $message);
if (!$success) {
$errorMessage = error_get_last()['message'];
}
?>
0
I'm doing this through a Linux hosting service, Sudarshan Rai 👑 could I ask you to point out the errors?
0
On Linux there's a `sendmail_path` in your php.ini that needs to point to a local "mail transfer agent" installation (an MTA, not necessarily sendmail)
If you are renting some webspace and not a whole server that should all be already configured for you though as you can't access the php.ini files.
Did `error_get_message()` do anything for you? Or do you have a more specific error message somewhere?
- 1
Here's the HTML:
<div class="container">
<a name="contact">
<form action="action_page.php" method="POST">
<label for="fname">Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your name">
<br>
<label for="mail">Email</label>
<input type="text" id="mail" name="email" placeholder="Your Email">
<br>
<label for="jtype">Job Type</label>
<input type="text" id="jtype" name="jobtype" placeholder="Electrical, plumbing, roofing, etc.">
<br>
<label for="message">Message</label>
<br>
<textarea id="msg" name="message" placeholder="Your message" style="height:200px">
</textarea>
<input type="submit" value="Submit">
</form>
</a>
</div>