Question

I've used this same form a number of times but this particular occasion it doesn't seem to actually be sending any email nor providing me any error messages or confirmation.

The output of the: print_r($_POST); from a test just a moment ago is the following:

Array ( [Name] => test name [Email] => test@test.com [Company] => example company [Position] => ceo [Captcha] => 1 )

So the form is grabbing all details correctly and attempting to pass them on, but no email or confirmation/error(s).

PHP / HTML

<?php
                   if (count($error)>=1) {
                       foreach($error as $one_error) {
                           echo '<h3>'.$one_error.'</h3>';
                           echo '<div class="clear"></div>';
                       }
                   }
                   if ($message_sent) {
                       echo '<h2>Thank you for your request. We will be in touch soon!</h2>';
                       echo '<hr class="hr" />';
                   }
                ?>

                <form action="index.php" method="POST">
                <span>
                    <label><strong>Name</strong></label><br />
                    <input type="text" name="Name" placeholder="Name" value="<?=$Name;?>" required />
                </span>
                <span>
                    <label><strong>Your Email Address</strong></label><br />
                    <input type="text" name="Email" placeholder="Email Address" value="<?=$Email;?>" required />
                </span>
            <br /><br />
                <span>
                    <label><strong>Company</strong></label><br />
                    <input type="text" name="Company" placeholder="Company" value="<?=$Company;?>" required />
                </span>
                <span>
                    <label><strong>Position</strong></label><br />
                    <input type="text" name="Position" placeholder="Company Position" value="<?=$Position;?>" required />
                </span>
            <br /> <br />
                <label><strong>Captcha</strong></label><br />
                <img src="<?php HTTP_HOST ?>/Contact/answer.php">
                <input type="text" placeholder="Enter Sum Calculation" name="Captcha" value="<?=$Captcha;?>" required />
            <div class="clear"></div><br />
                <input type="submit" value="Send Enquiry" />
                </form>

PHP (Inside of the same index.php file)

    <?php
    session_start();
 print_r($_POST);
// print_r($_SESSION['code']);
function isValidInetAddress($data, $strict = false) {
    $regex = $strict ? '/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' : '/^([*+!.&#$¦\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i';
    if (preg_match($regex, trim($data), $matches)) {
        return array($matches[1], $matches[2]);
    } else {
        return false;
    }
}
$Name = '';$Email = '';$Company = '';$Position = '';$Captcha = '';

if (isset($_POST)&&(isset($_POST['Submit'])&&(strlen($_POST['Submit'])>1))) {
    $error = array();
    if (isset($_POST['Name'])&&(strlen($_POST['Name'])>1)) {
        $Name = $_POST['Name'];
    } else {
        $error[]='Name is empty';
    }
    if (isset($_POST['Email'])&&(strlen($_POST['Email'])>1)) {
        $Email = $_POST['Email'];
    } else {
        $error[]='Email is empty';
    }
    if (isset($_POST['Company'])&&(strlen($_POST['Company'])>1)) {
        $Company = $_POST['Company'];
    } else {
        $error[]='Company is empty';
    }
    if (isset($_POST['Position'])&&(strlen($_POST['Position'])>1)) {
        $Position = $_POST['Position'];
    } else {
        $error[]='Position is empty';
    }
    if (isset($_POST['Captcha'])&&($_POST['Captcha']==$_SESSION['code'])) {
    } else {
        $error[]='Captcha is wrong';
    }
    if (count($error)<1) {
        $headers = 'From: jordan@gmail.com' . "\r\n" .
            'Reply-To: jordan@gmail.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

        $message ='New DiSC Profile Request'."\r\n";
        $message .= 'Name: '.$Name."\r\n";
        $message .= 'Email: '.$Email."\r\n";
        $message .= 'Company: '.$Company."\r\n";
        $message .= 'Position: '.$Position."\r\n";


        mail('jordan@gmail.com', 'New DiSC Profile Request', $message, $headers);
        // mail('galin@mangcreative.com', 'New Enquiry from Urban Country', $message, $headers);
        unset($Name);unset($Email);unset($Company);unset($Position);
        $message_sent = TRUE;
    }
} 
?>
Was it helpful?

Solution

Change the form submit button and give it a name

<input type="submit" value="Send Enquiry" />

to

<input type="submit" value="Send Enquiry" name="Submit"/>

OTHER TIPS

You need to have name="" on the button;

 <input type="submit" value="Send Enquiry" name="submit" />

You also don't need to have action="index.php" if the php is on the same page;

 <form action="" method="POST">

Also you don't need

if (isset($_POST)&&(isset($_POST['Submit'])&&(strlen($_POST['Submit'])>1))) {

Use: if (isset($_POST['submit'])===true) {

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top