0

I recently learned that I wasn't getting emails from my page contact form. It always worked before. So I have been trying different scripts that are out there including PHPEmailer and no cigar. I am including here the code for a very simple script.

<?php 
   $errors = '';
   $myemail = 'lotusms@outlook.com';//<-----Put Your email address here.
   if(empty($_POST['name'])  || 
      empty($_POST['email']) || 
      empty($_POST['phone']))
  {
      $errors .= "\n Error: all fields are required";
  }

  $name = $_POST['name']; 
  $email_address = $_POST['email']; 
  $phone = $_POST['phone']; 

  if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
     $email_address)) {
          $errors .= "\n Error: Invalid email address";
     }

  if( empty($errors)) {
      $to = $myemail; 
      $email_subject = "Contact form submission: $name";
      $email_body = "You have received a new message. ".
         " Here are the details:\n Name: $name \n Email: $email_address \n Message \n $phone"; 

      $headers = "From: $myemail\n"; 
      $headers .= "Reply-To: $email_address";

      mail($to,$email_subject,$email_body,$headers);
      //redirect to the 'index' page
      header('Location: ../index.php');
 } 
 ?>

Of course it doesn't work either (or I wouldn't be here, would I?) ... :)

I tested the host with the following test file and I got a positive "Email Sent!" which means the server is responding.

<?php
      mail('lotusms@outlook.com','Test mail','The mail function is working!');
      echo 'Mail sent!';
?>

So, what is going on? Any ideas, or perhaps a code you are positive it will work?

p.s. The HTML is simple

<form id="search" method="POST" name="contactform" action="contact-form-handler.php"> 
 .....

 <a onclick="document.getElementById('search').submit()">                                                                        
       <button type="submit" class="btn btn-default" value="SEND"/>Get Quote
 </a>

Thanks in advance

LOTUSMS
  • 10,317
  • 15
  • 71
  • 140
  • @John Conde, I read your answer on the other answer you made. I followed all the checks in the list and nothing. Any other ideas? p.s. I can't believe I missed that answer of yours. I thought I had covered everything. – LOTUSMS Dec 18 '14 at 01:06
  • Note that `mail()` is often unreliable. Try PHPMailer or SwiftMailer instead. – halfer Dec 18 '14 at 01:30
  • @halfer, I agree. I was using this one as a tester. I am actually trying to setup PHPMailer but I keep having connection fail. But all credentials seem to be correct – LOTUSMS Dec 18 '14 at 04:06
  • You may be able to turn on SMTP logging to see what is being sent. If you still think the creds are right, you can set up a demo account and ask the host to investigate. However I suspect you'll find out what the issue is before that stage. – halfer Dec 18 '14 at 15:25
  • I did exactly that. Dummy site, dummy email, etc.. And a test form with a PHPEmailer testing connection for a 'SMTP connect() failed. bool(true)' but I am getting a 'false' instead. I wish they didn't mark this question as duplicate. I really think I have a different issue. But oh well – LOTUSMS Dec 18 '14 at 15:46
  • It's a duplicate **as it stands**, as far as I can tell. But if you change it so that it is different, it can be reopened. I think you will have a lot more luck doing SMTP logging with PHPEmailer than `mail()`. Also, don't bother with a test form to start with. Write a console program to send a demo email, and turn on logging. If you get stuck turning on logging, then edit that into the question. – halfer Dec 18 '14 at 15:50

0 Answers0