-2

I don't see the issue with this contact form. It's a simple email contact form. Any help would be appreciated. The form goes through but nothing is submitted and no email is sent.

Also doesnt display any response on the page that the email went through. But apparently all the PHP is parsing correctly because I don't get an error.

<h2>Contact AirKrete</h2>
<?php 
$action=$_REQUEST['action']; 
if ($action=="")    /* display the contact form */ 
{ 
?>
<form action="" enctype="multipart/form-data" method="post"><p><label><input type="checkbox" name="locate " id="locate "><strong>Locate an Installer</strong></label><strong><label><input type="checkbox" name="become" id="become">Become an Installer</label></strong></p>
    <div class="left">Name:<div>
      <input name="name" type="text" id="name" size="40" />
    </div></div>
<div class="left">Email:<div><input name="mailfrom" type="text" size="40" /></div></div>
<div class="left">Street:<div><input name="street" type="text" id="street" size="40" /></div></div>
<div class="left">City:<div><input name="city" type="text" id="city" size="40" /></div></div>
<div class="left">State:<div><input name="state" type="text" id="state" size="10" /> Zip:
  <input name="zip" type="text" id="zip" size="15" />
</div></div>
<div class="left">Country:<div><input name="country" type="text" id="country" size="40" /></div></div>
<div class="left">Phone:<div><input name="phone" type="text" id="phone" size="40" /></div></div></p>

<p>The fields above are REQUIRED<br>
<strong>How did you hear about AirKrete<span style="font-size:11.0pt; ">®</span>? <br>
Please make a selection.<span id="sprycheckbox1"><span class="checkboxRequiredMsg"></span></span></strong></p><div class="radiox"><label><input type="radio" name="Connection" value="friend" id="Connection_0">Friend</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="jobspec" id="Connection_1">Job Specification</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="hgtv" id="Connection_2">HGTV Promotion</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="web" id="Connection_3">Web Browsing</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="radio" id="Connection_4">Radio</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="tv" id="Connection_5">TV</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="other" id="Connection_6">Other</label></div></p>
<p class="clear-fix">&nbsp;</p>
<div><p><strong>Comments:</strong><br></p></div>
<p><textarea name="Comments" cols="43" rows="10" id="Comments"></textarea></p>
<p><label>If you have Attachments....</label></p>
<p><input name="file_attachment" type="file" size="30" /></p>
<p>When completed please click Send Email Button</p>
   <input type="submit" value="Send Email" />

   <input type="hidden" name="redirect" value="http://www.airkrete.com/airkrete_thankyou.php" /><p>Thank You</p>
    </form>
<?php 
}  
else                /* send the submitted data */ 
{
$locate=$_REQUEST['locate'];
$become=$_REQUEST['become'];
$mailfrom=$_REQUEST['mailfrom'];
$street=$_REQUEST['street'];
$city=$_REQUEST['city'];
$state=$_REQUEST['state'];
$zip=$_REQUEST['zip'];
$country=$_REQUEST['country'];
$phone=$_REQUEST['phone'];
$connection=$_REQUEST['Connection'];
$comments=$_REQUEST['Comments'];
$name=$_REQUEST['name']; 
if ((($locate=="")&&($become==""))||($mailfrom=="")||($street=="")||($city=="")||($state=="")||($zip=="")||($country=="")||($phone=="")||($connection=="")||($name==""))
    { 
    echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
    } 
else{   
    if($locate==""){      
        $message==$name+" from "+$street+" "+city+" "+$state+" "+$zip+" "+$country+" sent you an email via the contact form on the airkrete website. "+$name+" would like to become an installer. "+$name+" Their phone number is "+$phone+". They heard about you from: "+$connection+" And left you the following comment: "+$comments;
    }else if($become==""){
        $message==$name+" from "+$street+" "+city+" "+$state+" "+$zip+" "+$country+" sent you an email via the contact form on the airkrete website. "+$name+" would like to locate an installer. "+$name+" Their phone number is "+$phone+". They heard about you from: "+$connection+" And left you the following comment: "+$comments;
    }else{
        $message==$name+" from "+$street+" "+city+" "+$state+" "+$zip+" "+$country+" sent you an email via the contact form on the airkrete website. "+$name+" would like to become an installer and would also like to locate one. "+$name+" Their phone number is "+$phone+". They heard about you from: "+$connection+" And left you the following comment: "+$comments;
    }
    $from="From: $name<$email>\r\nReturn-path: $email"; 
    $subject="Message sent using your contact form"; 
    mail("joseph.roberts@usa.com", $subject, $message, $from); 
    echo "Email sent!"; 
    } 
}   
?> 
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
J Robz
  • 185
  • 10
  • 1
    `+` doesn't concatenate in PHP. http://php.net/manual/en/language.operators.string.php `The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments.` – chris85 Dec 07 '15 at 03:29
  • I changed all the plus signs to '.'s. Yet still nothing changes. – J Robz Dec 07 '15 at 04:25
  • You have no element named `action`. So `if ($action=="")` is always true, so you should always get the HTML form. If it is a whitepage you have a syntax error; check your error logs.. – chris85 Dec 07 '15 at 04:32
  • @chris85 well i added but i still get nothing. Now the page doesnt even refresh when i submit. Whats strange though is that even without that line i did not get a syntax error. – J Robz Dec 07 '15 at 04:45
  • It wouldn't be a syntax error, PHP just didn't know what you wanted to happen. The answer below doesn't help you? `` is just HTML sooo shouldn't affect PHP in anyway.. – chris85 Dec 07 '15 at 04:49
  • @chris85. I posted that question before scrolling down haha.. – J Robz Dec 07 '15 at 04:55

1 Answers1

1

The fixes for you are as follows:

1) There is no element named 'action' in the code. change <input type="submit" value="Send Email" /> to <input type="submit" value="Send Email" name="action" />

2) + is not used for concatenation in PHP. Use . instead

3) == is not used for value assignment. Use = instead i.e. use $message = and not $message ==

Also, you have used $mail variable which is no where defined. Use $mailfrom instead, to which you have assigned the email value.

Also, there is a space in the name for the element locate remove that too.

Also the I have doubt about working of mail function as you have not set any header before sending mail.

Please check below links to get full details how mail function works in PHP and what parameters are needed to it.

http://www.w3schools.com/php/func_mail_mail.asp

http://php.net/manual/en/function.mail.php

Try the following code:

<h2>Contact AirKrete</h2>
<?php 
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "" ; 
    if ($action=="")    /* display the contact form */ 
    {
    ?>
        <form action="" enctype="multipart/form-data" method="post">
            <p>
                <label>
                    <input type="checkbox" name="locate" id="locate">
                    <strong>Locate an Installer</strong>
                </label>
                <strong>
                    <label>
                        <input type="checkbox" name="become" id="become">Become an Installer
                    </label>
                </strong>
            </p>
            <div class="left">
                Name:
                <div>
                    <input name="name" type="text" id="name" size="40" />
                </div>
            </div>
            <div class="left">
                Email:
                <div>
                    <input name="mailfrom" type="text" size="40" />
                </div>
            </div>
            <div class="left">
                Street:
                <div>
                    <input name="street" type="text" id="street" size="40" />
                </div>
            </div>
            <div class="left">
                City:
                <div>
                    <input name="city" type="text" id="city" size="40" />
                </div>
            </div>
            <div class="left">
                State:
                <div>
                    <input name="state" type="text" id="state" size="10" /> Zip:
                    <input name="zip" type="text" id="zip" size="15" />
                </div>
            </div>
            <div class="left">
                Country:
                <div>
                    <input name="country" type="text" id="country" size="40" />
                </div>
            </div>
            <div class="left">
                Phone:
                <div>
                    <input name="phone" type="text" id="phone" size="40" />
                </div>
            </div>
            <p>The fields above are REQUIRED<br>
                <strong>
                    How did you hear about AirKrete<span style="font-size:11.0pt; ">®</span>? <br>Please make a selection.
                    <span id="sprycheckbox1">
                        <span class="checkboxRequiredMsg"></span>
                    </span>
                </strong>
            </p>
            <div class="radiox"><label><input type="radio" name="Connection" value="friend" id="Connection_0">Friend</label></div>
            <div class="radiox"><label><input type="radio" name="Connection" value="jobspec" id="Connection_1">Job Specification</label></div>
            <div class="radiox"><label><input type="radio" name="Connection" value="hgtv" id="Connection_2">HGTV Promotion</label></div>
            <div class="radiox"><label><input type="radio" name="Connection" value="web" id="Connection_3">Web Browsing</label></div>
            <div class="radiox"><label><input type="radio" name="Connection" value="radio" id="Connection_4">Radio</label></div>
            <div class="radiox"><label><input type="radio" name="Connection" value="tv" id="Connection_5">TV</label></div>
            <div class="radiox"><label><input type="radio" name="Connection" value="other" id="Connection_6">Other</label></div></p>
            <p class="clear-fix">&nbsp;</p>
            <div><p><strong>Comments:</strong><br></p></div>
            <p><textarea name="Comments" cols="43" rows="10" id="Comments"></textarea></p>
            <p><label>If you have Attachments....</label></p>
            <p><input name="file_attachment" type="file" size="30" /></p>
            <p>When completed please click Send Email Button</p>
            <input type="submit" value="Send Email" name="action" />
            <input type="hidden" name="redirect" value="http://www.airkrete.com/airkrete_thankyou.php" /><p>Thank You</p>
        </form>
    <?php 
    } 
    else                /* send the submitted data */ 
    {
        $locate = isset($_REQUEST['locate']) ? $_REQUEST['locate'] : "" ;
        $become = isset($_REQUEST['become']) ? $_REQUEST['become'] : "" ;
        $mailfrom = $_REQUEST['mailfrom'];
        $street = $_REQUEST['street'];
        $city = $_REQUEST['city'];
        $state = $_REQUEST['state'];
        $zip = $_REQUEST['zip'];
        $country = $_REQUEST['country'];
        $phone = $_REQUEST['phone'];
        $connection = $_REQUEST['Connection'];
        $comments = $_REQUEST['Comments'];
        $name = $_REQUEST['name']; 

        if ((($locate == "") && ($become == "")) || ($mailfrom == "") || ($street == "") || ($city == "") || ($state == "") || ($zip == "") || ($country == "") || ($phone == "") || ($connection == "") || ($name == ""))
        { 
            echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
        } 
        else
        {   
            if($locate == "")
            {      
                $message = $name." from ".$street." ".$city." ".$state." ".$zip." ".$country." sent you an email via the contact form on the airkrete website. ".$name." would like to become an installer. ".$name." Their phone number is ".$phone.". They heard about you from: ".$connection." And left you the following comment: ".$comments;
            }
            else if($become == "")
            {
                $message = $name." from ".$street." ".$city." ".$state." ".$zip." ".$country." sent you an email via the contact form on the airkrete website. ".$name." would like to locate an installer. ".$name." Their phone number is ".$phone.". They heard about you from: ".$connection." And left you the following comment: ".$comments;
            }
            else
            {
                $message = $name." from ".$street." ".$city." ".$state." ".$zip." ".$country." sent you an email via the contact form on the airkrete website. ".$name." would like to become an installer and would also like to locate one. ".$name." Their phone number is ".$phone.". They heard about you from: ".$connection." And left you the following comment: ".$comments;
            }
            $from = "From: $name<$mailfrom>\r\nReturn-path: $mailfrom"; 
            $subject = "Message sent using your contact form";

            if(mail("joseph.roberts@usa.com", $subject, $message, $from)) 
                echo "Email sent!";
            else
                echo "Email not sent.";
        } 
    }   
?> 
Suyog
  • 2,472
  • 1
  • 14
  • 27
  • Why should the OP try the following code? An answer should explain to the OP what was fixed and preferably why.. – chris85 Dec 07 '15 at 04:36
  • 1
    @chris85 answer is edited.. :) – Suyog Dec 07 '15 at 04:39
  • @Suyog Thank you this works. The last issue I have is that it should only return that all fields should be filled out if both $locate and $become are equivalent to "", but as it is if either of them are equal to "" it returns that. – J Robz Dec 07 '15 at 04:54
  • @JRobz you will have to check whether the values are set or not. Please see the edited answer. I have use ternary operator for first two fields. Add that check to all the other values. Also check if the mail function has sent mail or not – Suyog Dec 07 '15 at 05:00