1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Contact Form ! Help me....

Discussion in 'HTML & Website Design' started by Nitrah, Oct 14, 2021.

  1. #1
    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 = '';//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
     
    Nitrah, Oct 14, 2021 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    You have a lot of problems here, only some of which are related to your actual issue.

    The biggest one server-side is you failed to grasp how mail() accepts arrays for headers in the new post PHP 5 era. When you use an array, it's supposed to be an ASSOCIATIVE array of index => value. This where you have this:

    
    $headers = array();
    $headers[] = "MIME-Version: 1.0";
    $headers[] = "Content-type: text/plain; charset=iso-8859-1";
    $headers[] = "From: {$name} <{$from}>";
    
    Code (markup):
    You should actually have:

    $headers = [
      "MIME-Version" => "1.0",
      "Content-type" => "text/plain; charset=iso-8859-1",
      "From" => "{$name} <{$from}>"
    ];
    
    Code (markup):
    I'm not sure that would bork the sending of the main message content, but given the lack of indexes on the headers, that could be what's messing things up.

    Now that said, your client-side code is a wreck. Placeholder is NOT a LABEL tag, don't do that you're telling large swaths of users to f*** off no matter how many artsy-fartsy know-nothings cream their panties over that. You really don't need the ID's on any of those since you have no labels pointing at them. The default type for a button is submit, most of your classes and DIV for nothing really need an axe swung at them, and where's your fieldset?

    A properly structured form looks more like this:

    <form id="mainContactForm" method="post" action="sendemail.php">
    	<fieldset>
    		<label>
    			Your Name<br>
    			<input type="text" name="name" required><br>
    		</label><label>
    			E-Mail Address<br>
    			<input type="email" name="email" required><br>
    		</label></label>
    			Subject<br>
    			<input type="text" name="subject" required><br>
    		</label><label>
    			Message<br>
    			<textarea rows="6" name="message" required><br>
    		</label>
    	</fieldset>
    	<div class="submitsAndHiddens">
    		<button>Submit</button>
    	</div>
    </form>
    Code (markup):
    If you need more classes than that, you're probably doing something wrong.

    Also is the document UTF-8 like all modern docs, if so the character encoding mismatch of declaring ISO-8859-1 server-side could be screwing with you.

    I'd also consider axing all those "variables for NOTHING" you're copying from $_POST for no good reason, and don't forget to validate EVERY value even if mail() now provides a degree of sanitation.
     
    deathshadow, Oct 16, 2021 IP