0

So I have a normal but long HTML form on this page

The PHP mail script for the form is:-

$to = "something@gmail.com";
$from = $_POST['contact_email'];
$subject = "Application form submission";

$message = "<h2>Tell us what you need?</h2>";
$message .= "Loan Amount Required ?";
$message .= "<br>";
$message .= $_POST['tell_loan_amount'];
$message .= "<br>";
$message .= "<br>";
$message .= "What For?";
$message .= "<br>";
$message .= $_POST['tell_what_for'];
/* and so on */

$headers = "From: $from" . "\r\n" ;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();

if( mail($to,$subject,$message,$headers)) {
 echo "<h1>Thank you for the Application</h1>";
 echo "<p>We will now review the application. This process normally takes 2-3 Business Hours. If we need to discuss any aspect of the application we will contact you. If you have any questions at all please do not hesitate to contact us on <strong>1300 815 462</strong></p>";
}
else {
 echo "failed";
}

Now the problem is that mail only gets sent sometimes. I have had several clients contact and said that they successfully reached the thank you page and received the success message but we never received the mail. And yes, not in Spam either.

Is it happening because it is set to gmail? Or is it happening because of incorrect encoding? (Our clients are filling form in English.) Or do I need to use mb_send_mail() instead of mail() and remove the encoding code altogether?

Grey-lover
  • 635
  • 3
  • 7
  • 21
  • gmail won't allow emails which doesn't match some criterias (smtp fix ip ?). You should try to use a smtp, for example sending mails from gmail smtp (with a gmail account), they will work. – Pierre Emmanuel Lallemant Jun 21 '18 at 08:56
  • https://stackoverflow.com/a/6666926/6049581 might be useful to read through. – Frits Jun 21 '18 at 08:56
  • 2
    Not an expert on the mail() function but I'd recommend using the [PHPMailer](https://github.com/PHPMailer/PHPMailer) library which fixes a lot of issues with the standard functions – Matt Jun 21 '18 at 08:56
  • 1
    It is best to avoid `mail()` since it does not give you much control over sending email. I suggest PHPMailer or SwiftMailer instead. – halfer Jun 21 '18 at 08:57

1 Answers1

0

use this command on you server it will output what happen to your sent mail :

tail -f /var/log/maillog

sometimes the provider block port 25

HamzaNig
  • 1,019
  • 1
  • 10
  • 33