0

Okay I'm working in jQuery mobile, and I just put in a PHP script for the email form. Everything works great, except nothing is being sent to my inbox. Here is the form and php code, could really use some help here. Been scratching my brain for the longest.

<?php
if($_SERVER['REQUEST_METHOD'] == "POST") 
{
    $message_body = 'First Name: ' . $_POST['firstName'] . '
            Last Name: ' . $_POST['lastName'] . '
            Email: ' . $_POST['email'] . '
            Company: ' . $_POST['company'] . '
            Phone: ' . $_POST['phone'] . '
            Services: ' . $_POST['serviceAreas'] .'
            Message: ' . $_POST['comments'];

    $to      = 'marvin.fai2@gmail.com';
    $subject = 'MobilizeWorldwide.com Contact Submission';
    $message = $message_body;
    $headers = 'From: info@mobilizeworldwide.com' . "\r\n" .
            'Reply-To: ' . $_POST['email'] . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);

    header('Location: ' . $_POST['thankspage']);
}
else
{
    echo 'There is no post information.';
}

HTML:

 <form method="post" action="email.php">
          <input type="text" name="firstName" placeholder="First name" required>
          <input type="text" name="lastName" placeholder="Last name" required>
          <input type="text" name="email" placeholder="Email Address" required>
          <input type="text" name="company" placeholder="Company">
          <input type="text" name="phone" placeholder="Phone Number">
          <fieldset>
            <legend>Please indicate service areas of interest, and select all that apply:</legend>
            <input id="airFrame" name="serviceArea" type="checkbox">
            <label for="airFrame">VISA</label>
            <input id="compMaint" name="serviceArea" type="checkbox">
            <label for="compMaint">AmEx</label>
            <input id="engineAPU" name="serviceArea" type="checkbox">
            <label for="engineAPU">Mastercard</label>
            <input id="engineAPULeas" name="serviceArea" type="checkbox">
            <label for="engineAPULeas">VISA</label>
            <input id="lMaint" name="serviceArea" type="checkbox">
            <label for="lMaint">AmEx</label>
            <input id="gTS" name="serviceArea" type="checkbox">
            <label for="gTS">Mastercard</label>
            <input id="onW" name="serviceArea" type="checkbox">
            <label for="onW">VISA</label>
            <input id="train" name="serviceArea" type="checkbox">
            <label for="train">AmEx</label>
          </fieldset>
          <textarea id="comments" name="comments" placeholder="Comments" rows="8"></textarea>
          <button type="submit" value="Submit" name="submit">
        </form>
  • 1
    Can you put this at the beginning of your email.php: `error_reporting(E_ALL)`, comment out the `header()` part and paste the error here plz. – Bokw Mar 29 '12 at 09:32
  • 1
    are you sending mail from localhost? is SMTP configured in your LOCALHOST? check what mail function returns you.. – Rukmi Patel Mar 29 '12 at 09:32
  • It's not the mail(), I've used this same script before minus the checkbox for my contact form on my portfolio and it works fine. Im doing it locally with wall, and it also didn't work on my web server –  Mar 29 '12 at 09:46
  • your script is correct, try using mailing server other than gmail you will get the result (yahoo or hotmail), infect you are receiving mails on gmail too but spam's, as i am getting while using your script. The issue i found is the header, gmail consider you as random person, please find your solution here [problem with php mail 'From' header](http://stackoverflow.com/questions/2014081/problem-with-php-mail-from-header) Best of luck! – m-t Mar 29 '12 at 10:52
  • @tariq Can you send me the link to where you have it working? I've tried different email addresses and still nothing. The gmail one was a last one I tried. –  Mar 29 '12 at 12:44
  • @Bokw I did that, and nothing happened. It just acted normally to what I described the situation to be. –  Mar 29 '12 at 12:48

1 Answers1

0

i didn't consider your html form as i believe your post method working fine and email.php getting all values as you set, here in my case i am assuming dummy values for checking you script,

<?php

$message_body = 'First Name: ' . "tariq" . '
        Last Name: ' . "sarwar" . '
        Email: ' . "mts@gmail.com" . '
        Company: ' . "renai" . '
        Phone: ' . "123456" . '
        Services: ' . "abcdef" .'
        Message: ' . "Test message" ;

$to      = 'mtarik.sarwar@gmail.com';
$subject = 'MobilizeWorldwide.com Contact Submission';
$message = $message_body;
$headers .= 'From: "user" <user@domain.com>' . "\r\n";

if(mail($to, $subject, $message, $headers)) echo "msg sent"; else echo 'There is no post information.';

?>

as i mentioned it before that i got the results but as spam for gmail, and working fine for other mailing servers;

enter image description here

m-t
  • 502
  • 5
  • 11
  • Thanks for posting this! I think the problem is the PHP mail server's where I work. This problem has arose before, so I'm in talks with our host to see if this can be fixed. I'll let you know if I need any more help. Thanks for all the truly helpful assistance, means a lot :n)!!!! –  Mar 29 '12 at 15:09