Form Not Sending Please Help

6 replies
So I have a simple form the php code to send shoots out the reply that it was sent but nothing coming in email - why?

PHP Code:
<?php
//if "email" variable is filled out, send email
  
if (isset($_POST['email']))  {
  
  
//Email information
  
$email_subject "New Credit Application";
  
$email_to "myemail@hotmail.com";
  
$email_from $_POST['email'];
  
$name $_POST['name'];
  
$phone $_POST['phone'];
  
$referral $_POST['selection'];
  
 
  
  
//send email
  
$email_message .= "Name: ".$name."\n";
 
    
$email_message .= "Phone Number: ".$phone."\n";
 
    
$email_message .= "Email: ".$email_from."\n";
 
    
$email_message .= "Selection: ".$referral."\n";
 
  
  
// create email headers
 
    
$headers 'From: '.$email_from."\r\n".
     
    
'Reply-To: '.$email_from."\r\n" .
     
    
'X-Mailer: PHP/' phpversion();
     
$send mail($email_to$email_subject$email_message$headers);
      
      
//Email response
      
if ($send) {
      echo 
"Thank you for contacting us!";
      }else {
          echo 
"Something Went Wrong";
      }
      }
      
?>
#form #sending
  • Profile picture of the author majick
    code looks okay, perhaps it is being filtered and so not received...
    check your spam folder and/or test a different email address?
    {{ DiscussionBoard.errors[10421334].message }}
  • Profile picture of the author robomedia
    To send email with 'mail' you need a mail server (like postfix,sendmail,exim etc) installed and set up on the server that's running your php. It might be very hard to do that if you're not an IT Pro / sys admin or know your stuff about mail servers, it's really tricky. If you can I would recommend using 3rd party mail server infrastructure like Mandrill or Mailgun . Both of them have free tiers ( 12,000 emails a month I think ) . And you can be pretty much sure that your mail will be delivered ( unless you're spamming , have high bounce rate etc ). It's quite simple to use i.e. SwiftMailer for PHP to send mails with either of those .
    {{ DiscussionBoard.errors[10421653].message }}
  • Profile picture of the author solidsoul
    Thank you for your reply - I find it strange cause this is the only domain on my server that won't send mail.. does it have anything to do with the fact that I'm working on Wordpress? the form itself is on a page in wordpress and form submitting to mydomain.com/phpfile.php again I get the email sent reply but nothing comes through - I have another site on the same server and get mail no problem??
    {{ DiscussionBoard.errors[10422340].message }}
  • Profile picture of the author solidsoul
    Ok following the advice here I tried a different email address to send to and that does work.... STRANGE hotmail not going to junk or anything just not going period??
    {{ DiscussionBoard.errors[10422347].message }}
    • Profile picture of the author kilgore
      My guess is hotmail's spam protection is preventing your message from getting through. If I had to guess why, I'd venture to say that it doesn't recognize the server you're sending from as being a valid sender for your FROM email address. If you want to ensure deliverability, your best bet is to go through an established transactional email service such as SendGrid, SES, or Mandril (and there are plenty of others). Alternatively, make sure your SPF records are set for your domain's DNS and that they point to the correct servers.
      {{ DiscussionBoard.errors[10422810].message }}
  • Profile picture of the author majick
    if you are on wordpress anyway, why not use the wp_mail function instead of mail()
    and put the php file in your /wp-content/mu-plugins/ folder ?

    ...you may need to wrap it as a function and add it to an action hook tho, eg. add_action('init','custom_email_sender');
    function custom_email_sender() {YOUR CODE;}

    then you just can just remove the form target that is pointing to the
    php file, because it will be handled by any wordpress url this way.

    this way you can install a mail logging plugin too and that might
    help you see what else might be going on there, or you could
    even install an smtp plugin to route the mail etc.
    {{ DiscussionBoard.errors[10422879].message }}

Trending Topics