Help solve the issue with sending the form from the site to the email address.
- I have enabled mail sending: cPanel > Settings > General > Sendmail > On
- I have not exceeded mail sending quota (50 emails/day)
- Form code on the page:
<div class="col-xs-12 col-md-8"> <div class="contact-form"> <form action="process.php" id="contact-form" method="post"> <div class="form-double"> <input type="text" id="form-name" name="form-name" placeholder="Ваше ім'я" required="required"> <input type="number" placeholder="Номер телефону"> </div> <div class="form-double"> <input type="email" name="form-email" name="email" id="form-email" placeholder="Електронна пошта" required="required"> <input type="text" name="form-subject" id="form-subject" placeholder="Тема" required="required"> </div> <textarea name="form-message" id="message" id="form-message" rows="5" required="required" placeholder="Текс попідомлення"></textarea> <button class="bttn bttn-primary">Надіслати</button> </form> </div> </div>
- Process.php code:
> <?php > // Configure your Subject Prefix and Recipient here > $subjectPrefix = '[Contact via website]'; > $emailTo = 'dimamed@bigmir.net'; > $errors = array(); // array to hold validation errors > $data = array(); // array to pass back data > if($_SERVER['REQUEST_METHOD'] === 'POST') { > $name = stripslashes(trim($_POST['name'])); > $email = stripslashes(trim($_POST['email'])); > $subject = stripslashes(trim($_POST['subject'])); > $message = stripslashes(trim($_POST['message'])); > if (empty($name)) { > $errors['name'] = 'Name is required.'; > } > if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { > $errors['email'] = 'Email is invalid.'; > } > if (empty($subject)) { > $errors['subject'] = 'Subject is required.'; > } > if (empty($message)) { > $errors['message'] = 'Message is required.'; > } > // if there are any errors in our errors array, return a success boolean or false > if (!empty($errors)) { > $data['success'] = false; > $data['errors'] = $errors; > } else { > $subject = "$subjectPrefix $subject"; > $body = ' > <strong>Name: </strong>'.$name.'<br /> > <strong>Email: </strong>'.$email.'<br /> > <strong>Message: </strong>'.nl2br($message).'<br /> > '; > $headers = "MIME-Version: 1.1" . PHP_EOL; > $headers .= "Content-type: text/html; charset=utf-8" . PHP_EOL; > $headers .= "Content-Transfer-Encoding: 8bit" . PHP_EOL; > $headers .= "Date: " . date('r', $_SERVER['REQUEST_TIME']) . PHP_EOL; > $headers .= "Message-ID: <" . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . $_SERVER['SERVER_NAME'] . '>' . PHP_EOL; > $headers .= "From: " . "=?UTF-8?B?".base64_encode($name)."?=" . "<$email>" . PHP_EOL; > $headers .= "Return-Path: $emailTo" . PHP_EOL; > $headers .= "Reply-To: $email" . PHP_EOL; > $headers .= "X-Mailer: PHP/". phpversion() . PHP_EOL; > $headers .= "X-Originating-IP: " . $_SERVER['SERVER_ADDR'] . PHP_EOL; > mail($emailTo, "=?utf-8?B?" . base64_encode($subject) . "?=", $body, $headers); > $data['success'] = true; > $data['message'] = 'Вітаю. Ваше повідомлення надіслано успішно.'; > } > // return all our data to an AJAX call > echo json_encode($data); > }