0

I Would like to send email using contact form in my company website, I was set the email configuration in php, here is my form :

<form action="sendmail.php" method="post" class="form form--contacts">
<input type="text" name="name" class="form__input" placeholder="Name" required>
<input type="email" name="email" class="form__input" placeholder="Email" required>
<input type="text" name="subject" class="form__input" placeholder="Subject" required>
<textarea class="form__textarea" name="text" placeholder="Text"></textarea>
<input class="form__btn" name="send" type="submit" value="Send">
</form>

and here is sendmail.php :

<?php
if($_POST['send']){
    $admin = 'myname@mydomain.co.id';

    $name   = htmlentities($_POST['name']);
    $email  = htmlentities($_POST['email']);
    $subject    = htmlentities($_POST['subject']);
    $text   = htmlentities($_POST['text']);
    $headers =  'MIME-Version: 1.0' . "\r\n";
    $headers .= 'From:'.$name.' <'.$email.'>' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $pengirim   = 'From: '.$name.' <'.$email.'>';

    if(mail($admin, $subject, $text, $headers)){
        echo 'SUCCESS: Mail Successfully sending';
    }else{
        echo 'ERROR: Error Sending Email';
    }
}else{
    header("Location: index.php");
}
?>
Gusti
  • 47
  • 1
  • 8

1 Answers1

0

There might be few reasons for junk mail detection.

First, you don't have "To: " in your headers.

Second, you rely on your system mail and you have no control over from which account you are sending mail from. If your "From:" header is different than your actual "mail from:" in your SMTP connection it's a red flag for spam filter.

You should try using PHPMailer instead of built in function. ( https://github.com/PHPMailer/PHPMailer ) or other alternative.

Some info may be found in this post: Sending email with PHP from an SMTP server

qocu
  • 289
  • 2
  • 9
  • "To: " is $admin – Gusti Nov 06 '18 at 04:09
  • is it in $headers ? – qocu Nov 06 '18 at 14:19
  • http://php.net/manual/en/function.mail.php take a look at example #5 and try to replicate to send it with static content, without the text from form. The problem might also be that you declare content in text/html and your $text may be just plain text. Also use on htmlentities() here might be troublesome, depending on what is entered by user but this shouldn't be main problem. – qocu Nov 06 '18 at 14:31
  • i have a new problem, the problem is the web are long loading after I send message, are you know the problem ? should I set username and password smtp in php.ini ? – Gusti Nov 07 '18 at 03:22