0

When I trying send emails with form in html 5 - this doesn't work and I don't know why.

Look: This is form in html:

<div class="col-md-4 col-sm-12">
                <div class="contact-form bottom">
                    <h2>send message</h2>
                    <form id="main-contact-form" name="contact-form" method="post" action="sendemail.php">
                        <div class="form-group">
                            <input type="text" name="name" class="form-control" required="required" placeholder="Your name">
                        </div>
                        <div class="form-group">
                            <input type="email" name="email" class="form-control" required="required" placeholder="Your e-mail">
                        </div>
                        <div class="form-group">
                            <textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="message..."></textarea>
                        </div>                        
                        <div class="form-group">
                            <input type="submit" name="submit" class="btn btn-submit" value="Submit">
                        </div>
                    </form>
                </div>
            </div>

and this is sendemail.php:

<?php
$name       = @trim(stripslashes($_POST['name'])); 
$from       = @trim(stripslashes($_POST['email'])); 
$subject    = @trim(stripslashes($_POST['subject'])); 
$message    = @trim(stripslashes($_POST['message'])); 
$to         = 'MYMAIL@gmail.com';//replace with your email

$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();

mail($to, $subject, $message, $headers);

die;

I hope you help me. Thanks a lot!

singhakash
  • 7,891
  • 6
  • 31
  • 65
MaryJanne
  • 9
  • 1
  • they are sent, but you do not receive them, because they most likely do not pass the spam filter. Try PHP Mailer for example – JRsz Dec 20 '15 at 16:38

1 Answers1

0

mail() functions expects headers parameter as String and you have passed an Array. Try to use as below :

$headers  = '';
$headers .= "MIME-Version: 1.0";
$headers .= "Content-type: text/plain; charset=iso-8859-1";
$headers .= "From: {$name} <{$from}>";
$headers .= "Reply-To: <{$from}>";
$headers .= "Subject: {$subject}";
$headers .= "X-Mailer: PHP/".phpversion();
AnkiiG
  • 3,468
  • 1
  • 17
  • 28