1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

My contact form is having problems sending emails

Discussion in 'PHP' started by kvela, Sep 16, 2015.

  1. #1
    Hi, I also have the same problem with my contact form, only that my form has json and i think it has also somthing to do with mi php.ini file set up. Im not very familiar with php, only with HTML, i made a website for my business and the contact form is having problems sending emails. When ever i ht the send button with the information on it, the only thing i get on the mails is:

    Name:
    Email:
    Subject:
    Message:
    Code (markup):
    I only get the labels, everything else is blank, this is my HTML code:

      <section id="contact-page">
      <div class="container">
      <div class="center">  
      <h2>Drop Your Message</h2>
      <p class="lead">Your opinion matters</p>
      </div>
      <div class="row contact-wrap" style="background-color:#FF9900">
      <div class="status alert alert-success" style="display: none"></div>
      <form id="main-contact-form" class="contact-form" name="contact-form" method="POST" action="sendemail.php">
      <div class="col-sm-5 col-sm-offset-1">
      <div class="form-group">
      <br><br>  <label>Name *</label>
      <input type="text" name="name" class="form-control" required="required">
      </div>
      <div class="form-group">
      <label>Email *</label>
      <input type="email" name="email" class="form-control" required="required">
      </div>
      <div class="form-group">
      <label>Phone</label>
      <input type="number" class="form-control">
      </div>
      <div class="form-group">
      <label>Company Name</label>
      <input type="text" class="form-control">
      </div>  
      </div>
      <div class="col-sm-5">
      <div class="form-group">
      <br><br><label>Subject *</label>
      <input type="text" name="subject" class="form-control" required="required">
      </div>
      <div class="form-group">
      <label>Message *</label>
      <textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
      </div>  
      <div class="form-group">
      <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
      </div>
      </div>
      </form>
      </div>
      </div>
      </section>
    HTML:

    and this is the sendemail.php file:

    <?php
      header('Content-type: application/json');
      $status = array(
      'type'=>'success',
      'message'=>'Thank you for contact us. As early as possible  we will contact you '
      );
    
      $name = @trim(stripslashes($_POST['name']));
      $email = @trim(stripslashes($_POST['email']));
      $subject = @trim(stripslashes($_POST['subject']));
      $message = @trim(stripslashes($_POST['message']));
    
      $email_from = $email;
      $email_to = 'contact@boasf-quinoa.com';//replace with your email
    
      $body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
    
      $success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
    
      echo json_encode($status);
      die;
      ?>
    PHP:

    And this is the mail function in the php.ini file:


    [mail function]
    ; For Win32 only.
    SMTP = localhost
    smtp_port = 25
    
    ; For Win32 only.
    
    ;sendmail_from = me@example.com
    
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    
    sendmail_path = /usr/sbin/sendmail -t -i
    Code (markup):


    I dont know where the problem might be, i think is in the ini file. I also copied the php processor file from another contact form that i have on anoteher website that is working fine, but when i put it in this site, is not working, it only send blank emails, please help, thanks
     
    kvela, Sep 16, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Well, it IS sending the email, since you get it, but for some reason the content of the email is not shown. It seems to me that the sendemail.php-file lacks any form of error-checking (not really smart), and for some reason it seems you're sending the $_POST-content via AJAX? (Since you return a JSON-object, I mean?)
    If you do, I would do the following: disable the AJAX-handler for the form, and comment out the die; from the sendemail.php-file, and echo out everything you receive in that file - that way, when you click "send" on the email-form, the sendemail-file will load, and you'll see what it receives.
     
    PoPSiCLe, Sep 17, 2015 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    A trick I learned to debugging POST requests (besides having to write to files) is switching it to get, so access sendemail.php?name=TestName&subject=TestSubject&message=TestMessage&email=

    and then get switching $_POST = $_GET. This allows you to directly debug your script and see what is wrong with it, once you figure it out remove the post to get switch and you are all set.
     
    ThePHPMaster, Sep 17, 2015 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Since it's brute-force resorting to @ to prevent errors from showing (one of the dumbest things you can do in PHP), what happens if you pull those? What errors does it return/output?

    Of course, given the incomplete train-wreck of how NOT to build a form you have there... well... goes hand in hand with the garbage known as bootcrap. Actually... heh... try changing POST to post... some browsers screw it up if you declare it in all uppercase depending on the doctype. Where's your fieldset? Where are your FOR attributes? Since "required" is HTML 5 only why are you wasting time on the XML declaration for it? What in BLAZES do you think you need all those DIV for? Unless you are using old-school Nyetscape 4 style scripting, why do you even have a NAME on the form?!?

    You also don't even have name attributes on all your input, if you have label/input pairs an ID really isn't optional, and remember in your final version to still check isset and !empty even on "required" fields since you cannot trust client-side validation.

    It is HIGHLY unlikely if you kicked the steaming pile of halfwit manure known as bootcrap to the curb (I'm assuming that's what it is from those garbage classes) for the markup of that form to vary much from:

    <form id="mainContactForm" method="post" action="sendemail.php">
      <h2>Drop Your Message</h2>
      <p>Your opinion matters</p>
      <fieldset>
    		<label for="contactName">Name <b>*</b></label>
    		<input type="text" name="name" id="contactName" required>
    		<br>
    		<label for="contactEmail">Email <b>*</label>
    		<input type="email" name="email" id="contactEmail" required>
    		<br>
    		<label for="contactNumber">Phone</label>
    		<input type="number" name="number" id="contactNumber">
    		<br>
    		<label for="contactCompany">Company Name</label>
    		<input type="text" name="company" id="contactCompany">
    		<br>
    		<label for="contactSubject">Subject <b>*</b></label>
    		<input type="text" name="subject" id="contactSubject" required>
    		<br>
    		<label for="contactMessage">Message <b>*</b></label>
    		<textarea name="message" id="contactMessage" rows="8" required></textarea>
    	</fieldset>
    	<div class="submitsAndHiddens">
    		<input type="submit" value="Submit Message">
    		<input type="hidden" name="hash" value="">
    	</div>
    </form>
    Code (markup):
    The "hash" would be a randomly generated value with a copy stored in $_SESSION with a timestamp/expiration. This can prevent accidental resends from a user hitting "back" or mashing the submit over and over, as well as block a few simpler spambots. (without the screwing around with header() redirect nonsense you'll see some folks use).

    It is HIGHLY unlikely you need more markup than that, and that method="POST" instead of method="post" may very well be all that was wrong in terms of it actually working... though those input you had without name on them could also cause all sorts of oddball results.
     
    deathshadow, Sep 17, 2015 IP