0

I have a PHP contact form on my site which was working last week, I have gone to try it today and it is not now. I put the contact form on a few more pages on the site, would that be a problem? I have now deleted all the other pages which my contact form was on from the FTP to see if that was an issue, but it still is not coming through to the receiever email.

<form action="bat/MailHandler.php" method="post" form id="contact-form" class="contact-form">
                      <div class="success"> Contact form submitted! <strong>We will be in touch soon.</strong> </div>
                      <fieldset>
                        <div class="coll-1" style="width:100%">
                          <div class="txt-form">Name<span>*</span></div>
                          <label class="name">
                            <input type="text" value="Name*:"><br>
                            <span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span> </label>
                        </div>
                        <div class="coll-2" style="width:100%">
                          <div class="txt-form">Email<span>:</span></div>
                          <label class="email">
                            <input type="email" value="E-mail*:"><br>
                            <span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span> </label>
                        </div>
                        <div class="coll-3" style="width:100%">
                          <div class="txt-form">phone:</div>
                          <label class="phone notRequired">
                            <input type="tel" value="Phone:"><br>
                            <span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span> </label>
                        </div>
                        <div class="clear"></div>
                        <div>
                          <div class="txt-form">Comment<span>*</span></div>
                          <label class="message">
                            <textarea>Message*:</textarea><br>
                            <span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>
                        </div>
                        <div class="clear"></div>
                      </fieldset>
                      <div class="buttons-wrapper clearfix"><a href="#" class="btn-link btn-link2" data-type="submit">submit<span></span></a><strong>*REQUIRED FIELDS</strong></div>
                    </form>
            </div>
        </div>
    </div>
</div>

JS here:

//forms
;(function($){
 $.fn.forms=function(o){
  return this.each(function(){
   var th=$(this)
    ,_=th.data('forms')||{
     errorCl:'error',
     emptyCl:'empty',
     invalidCl:'invalid',
     notRequiredCl:'notRequired',
     successCl:'success',
     successShow:'4000',
     mailHandlerURL:'http://ryanterpilowski.co.uk/urofoam/bat/MailHandler.php',
     ownerEmail:'ryan@urofoam.co.uk',
     stripHTML:true,
     smtpMailServer:'localhost',
     targets:'input,textarea',
     controls:'a[data-type=reset],a[data-type=submit]',
     validate:true,
     rx:{
      ".name":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
      ".state":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
      ".email":{rx:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,target:'input'},
      ".phone":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
      ".fax":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
      ".message":{rx:/.{20}/,target:'textarea'}
     },
     preFu:function(){
      _.labels.each(function(){
       var label=$(this),
        inp=$(_.targets,this),
        defVal=inp.val(),
        trueVal=(function(){
           var tmp=inp.is('input')?(tmp=label.html().match(/value=['"](.+?)['"].+/),!!tmp&&!!tmp[1]&&tmp[1]):inp.html()
           return defVal==''?defVal:tmp
          })()
       trueVal!=defVal
        &&inp.val(defVal=trueVal||defVal)
       label.data({defVal:defVal})        
       inp
        .bind('focus',function(){
         inp.val()==defVal
          &&(inp.val(''),_.hideEmptyFu(label),label.removeClass(_.invalidCl))
        })
        .bind('blur',function(){
         _.validateFu(label)
         if(_.isEmpty(label))
          inp.val(defVal)
          ,_.hideErrorFu(label.removeClass(_.invalidCl))           
        })
        .bind('keyup',function(){
         label.hasClass(_.invalidCl)
          &&_.validateFu(label)
        })
       label.find('.'+_.errorCl+',.'+_.emptyCl).css({display:'block'}).hide()
      })
      _.success=$('.'+_.successCl,_.form).hide()
     },
     isRequired:function(el){       
      return !el.hasClass(_.notRequiredCl)
     },
     isValid:function(el){       
      var ret=true
      $.each(_.rx,function(k,d){
       if(el.is(k))
        ret=d.rx.test(el.find(d.target).val())          
      })
      return ret       
     },
     isEmpty:function(el){
      var tmp
      return (tmp=el.find(_.targets).val())==''||tmp==el.data('defVal')
     },
     validateFu:function(el){       
      el.each(function(){
       var th=$(this)
        ,req=_.isRequired(th)
        ,empty=_.isEmpty(th)
        ,valid=_.isValid(th)        
       
       if(empty&&req)
        _.showEmptyFu(th.addClass(_.invalidCl))
       else
        _.hideEmptyFu(th.removeClass(_.invalidCl))
       
       if(!empty)
        if(valid)
         _.hideErrorFu(th.removeClass(_.invalidCl))
        else
         _.showErrorFu(th.addClass(_.invalidCl))        
      })
     },
     getValFromLabel:function(label){
      var val=$('input,textarea',label).val()
       ,defVal=label.data('defVal')        
      return label.length?val==defVal?'nope':val:'nope'
     }
     ,submitFu:function(){
      _.validateFu(_.labels)       
      if(!_.form.has('.'+_.invalidCl).length)
       $.ajax({
        type: "POST",
        url:_.mailHandlerURL,
        data:{
         name:_.getValFromLabel($('.name',_.form)),
         email:_.getValFromLabel($('.email',_.form)),
         phone:_.getValFromLabel($('.phone',_.form)),
         fax:_.getValFromLabel($('.fax',_.form)),
         state:_.getValFromLabel($('.state',_.form)),
         message:_.getValFromLabel($('.message',_.form)),
         owner_email:_.ownerEmail,
         stripHTML:_.stripHTML
        },
        success: function(){
         _.showFu()
        }
       })   
     },
     showFu:function(){
      _.success.slideDown(function(){
       setTimeout(function(){
        _.success.slideUp()
        _.form.trigger('reset')
       },_.successShow)
      })
     },
     controlsFu:function(){
      $(_.controls,_.form).each(function(){
       var th=$(this)
       th
        .bind('click',function(){
         _.form.trigger(th.data('type'))
         return false
        })
      })
     },
     showErrorFu:function(label){
      label.find('.'+_.errorCl).slideDown()
     },
     hideErrorFu:function(label){
      label.find('.'+_.errorCl).slideUp()
     },
     showEmptyFu:function(label){
      label.find('.'+_.emptyCl).slideDown()
      _.hideErrorFu(label)
     },
     hideEmptyFu:function(label){
      label.find('.'+_.emptyCl).slideUp()
     },
     init:function(){
      _.form=_.me      
      _.labels=$('label',_.form)

      _.preFu()
      
      _.controlsFu()
              
      _.form
       .bind('submit',function(){
        if(_.validate)
         _.submitFu()
        else
         _.form[0].submit()
        return false
       })
       .bind('reset',function(){
        _.labels.removeClass(_.invalidCl)         
        _.labels.each(function(){
         var th=$(this)
         _.hideErrorFu(th)
         _.hideEmptyFu(th)
        })
       })
      _.form.trigger('reset')
     }
    }
   _.me||_.init(_.me=th.data({forms:_}))
   typeof o=='object'
    &&$.extend(_,o)
  })
 }
})(jQuery)
$(window).load(function(){
 $('#contact-form3').forms({
 ownerEmail:'ryan@urofoam.co.uk'
   })
   $('#contact-form2').forms({
 ownerEmail:'ryan@urofoam.co.uk'
   })
   $('#contact-form').forms({
 ownerEmail:'ryan@urofoam.co.uk'
   })
})

PHP:

<?php
$owner_email = $_POST["ryan@urofoam.co.uk"];
$headers = 'From:' . $_POST["email"] . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
$subject = 'A message from your site visitor ' . $_POST["name"];
$messageBody = "";

if($_POST['name']!='nope'){
    $messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['email']!='nope'){
    $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}else{
    $headers = '';
}
if($_POST['state']!='nope'){        
    $messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['phone']!='nope'){        
    $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}   
if($_POST['fax']!='nope'){      
    $messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['message']!='nope'){
    $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}

if($_POST["stripHTML"] == 'true'){
    $messageBody = strip_tags($messageBody);
}

try{
    if(!mail($owner_email, $subject, $messageBody, $headers)){
        throw new Exception('mail failed');
    }else{
        echo 'mail sent';
    }
}catch(Exception $e){
    echo $e->getMessage() ."\n";
}

?>

Ryan Terps
  • 19
  • 2
  • 1
    Are you getting any errors? Have you tried any debugging? – Burki Jul 01 '15 at 09:32
  • The contact form seems to have no errors, and when you write a message it says the form has been sent and everything... I just don't receive anything, but it was working when I tried it the other week. – Ryan Terps Jul 01 '15 at 09:35
  • How would I go about de-bugging? – Ryan Terps Jul 01 '15 at 09:36
  • standard bebugging would be to generate output at various places, to see where the code fails. Apart from that: have you checked your spam folder? Assuming from your code that the mails are being sent to yourself? – Burki Jul 01 '15 at 09:41
  • At least enable `error_reporting` whenever something doesn't work. `$_POST["ryan@urofoam.co.uk"]` won't do what you think it does. – mario Jul 01 '15 at 09:42
  • Please check for error message generated by `mail()` function if any and let me know what is it. We require to first check with `mail()` is working correctly or not. – AddWeb Solution Pvt Ltd Jul 01 '15 at 09:44
  • Sorry where do I do this? @AddWebSolutionPvtLtd – Ryan Terps Jul 01 '15 at 09:49
  • @Burki I have tried it with my urofoam address and my hotmail one, and it still has nothing receieved... – Ryan Terps Jul 01 '15 at 09:56
  • Please paste the provide code before your `try{}`. print("
    MAIL_ERROR ::");
    print(mail($owner_email, $subject, $messageBody, $headers));
    print("
    "); print("
     LAST_ERROR ::");
    print(error_get_last());
    print("
    "); exit; Let me know what it prints?
    – AddWeb Solution Pvt Ltd Jul 01 '15 at 10:03
  • I have never heard of this.. as you can tell my PHP skills are fairly limited... do you want me to print this? if so where? @AddWebSolutionPvtLtd – Ryan Terps Jul 01 '15 at 10:10
  • Fixed @AddWebSolutionPvtLtd Thank you so much! – Ryan Terps Jul 01 '15 at 10:42

0 Answers0