Hi everyone,

I have problem with form at my site. When you fill the text boxes it works fine but when you click SEND, the site is refreshing, form is clear and no message has been sent. My knowledge about PHP is very low. I found the tutorial which shows how to make that kind of form. I watched it 3 times and till now I don't know what is wrong.

form is on this site -->

I have 3 files which whould operate the form.

formularz.php

<div class="form" <? if(isset($_POST['sender'])) { echo "style=\"display:none;\""; } ?>>
	  <form action="" method="post" id="form1">
      <input type="hidden" name="sender" value="true">
            <fieldset>
              <legend>Formularz kontaktowy</legend>
              <li><span id="sprytextfield1">
              <label for="imieinazwisko">Imię i Nazwisko:</label>
              <input name="imieinazwisko" type="text" id="imieinazwisko" tabindex="1" maxlength="30">
              <span class="textfieldRequiredMsg">Pole wymagane</span><span class="textfieldMinCharsMsg">Za mało znaków</span></span></li>
              <li><span id="sprytextfield2">
              <label for="adresemail2">Adres e-mail:</label>
              <input type="text" name="adresemail" id="adresemail2" tabindex="2">
              <span class="textfieldRequiredMsg">Błędny adres email</span><span class="textfieldInvalidFormatMsg">Błędny adres e-mail</span></span></li>
              <li><span id="spryconfirm1">
                <label for="walidacjaemail">Podaj ponownie e-mail:</label>
                <input type="text" name="walidacjaemail" id="walidacjaemail" tabindex="3">
                <span class="confirmRequiredMsg">Pole wymagane</span><span class="confirmInvalidMsg">Adres się nie zgadza</span></span>
              </li>
              <li><span id="sprytextfield3">
              <label for="numertelefonu">Telefon:</label>
              <input type="text" name="numertelefonu" id="numertelefonu" tabindex="4">
              <span class="textfieldInvalidFormatMsg">Niewłaściwy numer</span><span class="textfieldMinCharsMsg">Niewłaściwy numer</span><span class="textfieldMinValueMsg">Za mało cyfr</span></span></li>
              <li>
                <label for="miasto">Miasto:</label>
                <input name="miasto" type="text" id="miasto" tabindex="5" maxlength="15">
              </li>
              <li>
              <span id="sprytextarea1">
              <label for="wiadomosc2">Wiadomość:</label>
              <textarea name="wiadomosc" id="wiadomosc2" cols="45" rows="5" tabindex="6"></textarea>
              <span class="textareaRequiredMsg">Pole wymagane</span><span class="textareaMinCharsMsg">Za mało znaków</span></span></li>
             
<li>
              
              <input type="submit" name="wyslij" id="wyslij" value="Wyślij" tabindex="6">
            </fieldset>
	  </form>
	  </li>
  		 </ul>
              
    
  
 
	  </div>

second file: jak_kupic.html (I paste only form's DIV)

<div class="form">
	  <form action="#" method="post" name="form1" id="form1">
            <fieldset>
              <legend>Formularz kontaktowy</legend>
              <li><span id="sprytextfield1">
              <label for="imieinazwisko">Imię i Nazwisko:</label>
              <input name="imieinazwisko" type="text" id="imieinazwisko" tabindex="1" maxlength="30">
              <span class="textfieldRequiredMsg">Pole wymagane</span><span class="textfieldMinCharsMsg">Za mało znaków</span></span></li>
              <li><span id="sprytextfield2">
              <label for="adresemail2">Adres e-mail:</label>
              <input type="text" name="adresemail" id="adresemail2" tabindex="2">
              <span class="textfieldRequiredMsg">Błędny adres email</span><span class="textfieldInvalidFormatMsg">Błędny adres e-mail</span></span></li>
              <li><span id="spryconfirm1">
                <label for="walidacjaemail">Podaj ponownie e-mail:</label>
                <input type="text" name="walidacjaemail" id="walidacjaemail" tabindex="3">
                <span class="confirmRequiredMsg">Pole wymagane</span><span class="confirmInvalidMsg">Adres się nie zgadza</span></span>
              </li>
              <li><span id="sprytextfield3">
              <label for="numertelefonu">Telefon:</label>
              <input type="text" name="numertelefonu" id="numertelefonu" tabindex="4">
              <span class="textfieldInvalidFormatMsg">Niewłaściwy numer</span><span class="textfieldMinCharsMsg">Niewłaściwy numer</span><span class="textfieldMinValueMsg">Za mało cyfr</span></span></li>
              <li>
                <label for="miasto">Miasto:</label>
                <input name="miasto" type="text" id="miasto" tabindex="5" maxlength="15">
              </li>
              <li>
              <span id="sprytextarea1">
              <label for="wiadomosc2">Wiadomość:</label>
              <textarea name="wiadomosc" id="wiadomosc2" cols="45" rows="5" tabindex="6"></textarea>
              <span class="textareaRequiredMsg">Pole wymagane</span><span class="textareaMinCharsMsg">Za mało znaków</span></span></li>
             
<li>
              
              <input type="submit" name="wyslij" id="wyslij" value="Wyślij" tabindex="6">
            </fieldset>
	  </form>
	  </li>
  		 </ul>
</div>

third file: jak_kupic.php (pasted only form's DIV)

<div class="form_field">
 	 <img src="images/jak_zamawiac_02.jpg" width="1024" height="661" alt="formularz">
  <?
  
  if(isset($_POST["sender"]))
  {
	  
  $imie=$_POST['imieinazwisko'];
  $email=$_POST['adresemail'];
  $telefon=$_POST['telefon'];
  $miasto=$_POST['miasto'];
  $wiadomosc=$_POST['wiadomosc'];
  
  //Potwierdzenie dla użytkownika
  $reply_subject= 'Zapytanie ze strony Hogar';
  $reply_body = 'Witamy serdecznie,\nOtrzymaliśmy Państwa wiadomość. Odezwiemy się najprędzej jak to mozliwe.\n\nZ poważaniem\nBiokominki Hogar';
  $reply_email = 'biuro@hogar-biokominki.pl';
  
  //Wysyłanie do Hogar
  $to = 'biuro@hogar-biokominki.pl';
  $from = $imie . "<" . $email .">";
  $subject = 'Zapytanie ze strony Hogar';
  $body="\n\nImię i Nazwisko" . $imie . "\n\nEmail: " . $email . "\n\nTelefon" . $telefon . "\n\nMiasto" . $miasto . "\n\nWiadomość:" . $wiadomosc;
  $coding = "Content-Type: text/plain; charse=utf-8 \nContent-Transfer-Encoding: 8bit";
  
  if(mail($to, $subject, $body, "From: " . $from . "\n"  . $coding))
  {
	  if(mail($email, $reply_subject, $reply_body, "From: " . $reply_email . "\n" . $coding))
	  {
		  echo"<p class=\"dziekujemy\"> Dziekujemy za wysłanie wiadomości!</p>";
	  }
	  else
	  {
    	   echo"<p class=\"dziekujemy\">Formularz nie został wysłany. Spróbuj ponownie.</p>";
	  }
  }
  }
  require_once("formularz.php");
  ?>
  
  		
  
  </div>

Looking forward to hearing from you guys!

Dani AI

Generated

Brief summary and likely cause (short)
As and pointed out, the form needs to submit to a PHP endpoint so the mailer code actually runs. Your observation that the form works when sent from /jak_kupic.php but not from /jak_kupic.html shows the same thing: a .html page is not parsed by PHP by default, so posting to it will only reload the page and clear the fields.

Practical checklist to fix the form

  • Ensure the form’s action explicitly targets the PHP handler (or make the page that contains the form a .php page). Leaving action empty or using “#” posts back to the current page, which will fail if that file isn’t executed by PHP.
  • Match input names to the $_POST keys the script reads. A mismatch (for example phone field name vs the PHP key) will make variables empty.
  • Use full PHP tags (<?php ... ?>) rather than short <? so the code runs on hosts where short_open_tag is disabled.
  • Fix mail headers and encoding: use a correct header string like Content-Type: text/plain; charset=utf-8 and separate headers with CRLF (\r\n). Misspellings or malformed headers can break delivery.
  • Don’t put arbitrary user-supplied email directly into the From header — use a domain mailbox for From and put the user address in Reply-To to reduce spam rejection and avoid header-injection risks.

How to test and debug
Turn on error reporting temporarily and create a tiny test script that calls mail() and prints its boolean result. If mail() returns false, the server MTA or SMTP settings need attention — check your host’s mail logs or contact support (as suggested). If mail() returns true but messages don’t arrive, check spam, SPF/DKIM, and consider sending via authenticated SMTP (PHPMailer/other) instead of mail().

Final notes
Validate and sanitize all inputs (use filter_var for emails) and log form submissions to a file during debugging so you can distinguish form-processing bugs from mail-delivery problems. This approach will make the cause clear and help avoid repeating the same layout/processing mismatch that observed.

Recommended Answers

All 5 Replies

Shouldn't the form's action attribute point to your PHP file ?

1) open formularz.php in line number 2 set action to jak_kupic.php

<form action="jak_kupic.php" method="post" id="form1">

save formularz.php and upload on server


2) DO NOT open jak_kupic.html. now open

I have changed "form action". Uploaded it to the server. Link /.formularz.php looks like my grandmother's teeth, and in /jak_kupic.html still nothings changed.
BUT!
Strange situation is when you send a form from /jak_kupic.php it works fine. But the layout is not looking good :/
What now should I change?

Hi Refer to

Did you set up your SMPT for the email so it knows how to send it?
smpt:
smpt_port:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.