1

my mail sender php is not works. I made a "succesfull" message in HTML which is needs to show after the mail sent succesfully. Now, the message shows up correctly but the mail is not arrives. I tried different paths to the my php file (./inc/... . php ; /inc/... .php ; inc/... . php) but it is not helped to solve my problem. This is my HTML:

            <!-- form -->
            <form name="contactForm" id="contactForm" method="post" action="inc/sendEmail.php">
         <fieldset>

                  <div class="form-field">
          <input name="contactName" type="text" id="contactName" placeholder="Név" value="" minlength="2" required="">
                  </div>
                  <div class="form-field">
             <input name="contactEmail" type="email" id="contactEmail" placeholder="Email" value="" required="">
                </div>
                  <div class="form-field">
             <input name="contactSubject" type="text" id="contactSubject" placeholder="Tárgy" value="">
                </div>                       
                  <div class="form-field">
                   <textarea name="contactMessage" id="contactMessage" placeholder="Üzenet" rows="10" cols="50" required=""></textarea>
                </div>                      
                 <div class="form-field">
                     <button class="submitform">Küldés</button>
                     <div id="submit-loader">
                        <div class="text-loader">Küldés...</div>                             
                 <div class="s-loader">
           <div class="bounce1"></div>
           <div class="bounce2"></div>
           <div class="bounce3"></div>
        </div>
       </div>
                  </div>

         </fieldset>
        </form> <!-- Form End -->

And this is my PHP:

<?php

$siteOwnersEmail = 'johndoe@123.xyz';


if($_POST) {

   $name = trim(stripslashes($_POST['contactName']));
   $email = trim(stripslashes($_POST['contactEmail']));
   $subject = trim(stripslashes($_POST['contactSubject']));
   $contact_message = trim(stripslashes($_POST['contactMessage']));

   // Check Name
 if (strlen($name) < 2) {
  $error['name'] = "Name error msg";
 }
 // Check Email
 if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
  $error['email'] = "Email error msg";
 }
 // Check Message
 if (strlen($contact_message) < 15) {
  $error['message'] = "Message error msg";
 }
   // Subject
 if ($subject == '') { $subject = "Contact Form Submission"; }


   // Set Message
   $message .= "Email from: " . $name . "<br />";
 $message .= "Email address: " . $email . "<br />";
   $message .= "Message: <br />";
   $message .= $contact_message;
   $message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";

   // Set From: header
   $from =  $name . " <" . $email . ">";

   // Email Headers
 $headers = "From: " . $from . "\r\n";
 $headers .= "Reply-To: ". $email . "\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
 $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


   if (!$error) {

      ini_set("sendmail_from", $siteOwnersEmail); // for windows server
      $mail = mail($siteOwnersEmail, $subject, $message, $headers);

  if ($mail) { echo "OK"; }
      else { echo "Error message... :("; }
  
 } # end if - no validation error

 else {

  $response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
  $response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
  $response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
  
  echo $response;

 } # end if - there was a validation error

}

?>

1 Answers1

0

First try a simple mail test to check if your server is able to send that. If not you might need to setup a SMTP server.

Simple Mail Test: Check here

uday8486
  • 1,203
  • 2
  • 13
  • 22