October 14, 20214 yr Hello everyone , i have a problem with my contact Form .... Ι fill in the fields of the contact form and click send. The mail goes normally but blank. Without any of the data I put in the fields. Look my Code. sendemail.php File <?php $name = $_POST['name']; $from = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $to = 'info@geapellas.gr';//replace with your email $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/plain; charset=iso-8859-1"; $headers[] = "From: {$name} <{$from}>"; mail($to, $subject, $message, $headers); die; Html Contact index File <form id="main-contact-form" name="contact-form" method="post" action="sendemail.php"> <div class="form-group"> <input type="text" placeholder="Όνομα" class="form-control" name="name" id="name"> </div> <div class="form-group"> <input type="email" placeholder="Email" class="form-control" name="email" id="email"> </div> <div class="form-group"> <input type="text" placeholder="Θέμα" class="form-control" name="subject" id="subject"> </div> <div class="form-group"> <textarea rows="6" placeholder="Μήνυμα" class="form-control" name="message" id="message"></textarea> </div> <button type="submit" id="contact-submit" class="btn btn-primary">Αποστολή</button> </form> Can someone find the problem please ? Thanks
October 15, 20214 yr It’s probably being block by your host. Many don’t allow post data in the from name/email fields. You also need to validate the data. Right now you have left an open door for anyone to hack your site.
June 20, 20242 yr Hi, I have tried and checked your code in sendemail.php I think there is some problem in $headers[], try this code, it works fine. <?php $name = $_POST['name']; $from = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $to = 'info@geapellas.gr';//replace with your email $headers = "From: $from"; mail($to, $subject, $message, $headers); die; ?>
September 5, 20241 yr The issue occurs because you are passing an array of headers into the mail() function, while the mail() function expects a string for the headers. You need to convert the headers array into a string before passing it to the function. Here’s how to fix it: <?php // Retrieve form data $name = $_POST['name']; $from = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $to = 'info@geapellas.gr'; // Replace with your email // Build headers $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1" . "\r\n"; $headers .= "From: {$name} <{$from}>" . "\r\n"; // Send email mail($to, $subject, $message, $headers); // Optional: Redirect or show success message echo "Email sent successfully!"; die; ?> Key Changes: 1. Headers as a String: Instead of using an array for $headers, I concatenated the headers into a string, which is required by the mail() function. 2. Newline Characters (\r\n): Each header line is separated using \r\n, which is the standard for email headers.
Create an account or sign in to comment