SetoKaiba
SetoKaiba

Reputation: 31

Some PHP variables not appearing when contact us form is used

below is the php code for my contact form, the website is live at the moment and when i use the form to send a query using the contact us form, not all information gets through:

In the email that i receive, the only information that comes through is $subject and the message ($name would like to move in on $move.\r\n\n";). No other data that the client inputs on the website is listed in the email. I have looked at the code and cant seem to find what is wrong.

I would appreciate any help.

<?php
if(!$_POST) exit;

    $to       = '[email protected]'; 
    $name     = $_POST['txtname'];
    $email    = $_POST['txtemail'];
    $phone    = $_POST['txtphone'];
    $comp     = $_POST['txtcomp'];
    $emp      = $_POST['txtemp'];
    $move     = $_POST['txtmove'];
    $comment  = $_POST['txtmessage'];

    if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }

     $subject = 'You\'ve been contacted by ' . $name . '.';

     $msg  = "You have been contacted by $name.\r\n\n";


     $msg .= "$comment\r\n\n";
     $msg .= "You can contact $name via email, $email.\r\n\n";
     $msg  = "You can call $name on $phone.\r\n\n";
     $msg  = "$name has $emp employees and the company name is $comp.\r\n\n";
     $msg  = "$name would like to move in on $move.\r\n\n";


     $msg .= "-------------------------------------------------------------------------------------------\r\n";

     if(@mail($to, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
     {
         echo "<span class='success-msg'>Thanks for Contacting Us, We will call back to you soon.</span>";
     }
     else
     {
         echo "<span class='error-msg'>Sorry your message was not sent, Please try again.</span>";
     }
?>

Thanks for the replies and suggestions, below is the HTML for the form:

            <div id="map"></div> 
            <div class="dt-sc-margin50"></div>
            <div class="container">
                <div class="column dt-sc-three-fourth first">
                    <div class="hr-title">
                        <h3>Request A Call Back</h3>
                        <div class="title-sep">
                        </div>
                    </div>
                    <form method="post" class="dt-sc-contact-form" action="php/send.php" name="frmcontact">
                        <div class="column dt-sc-one-third first">
                            <p> <span class="auto-style2">Your Name</span><span> <input type="text" placeholder="Name*" name="txtname" maxlength="25" value="" required /> </span> </p>
                        </div>
                        <div class="column dt-sc-one-third">
                            <p><span class="auto-style2">Your Email Address<span> <input type="email" placeholder="Email*" name="txtemail" value="" required /> </span> </p>
                        </div>
                        <div class="column dt-sc-one-third">
                            <p><span class="auto-style2">Your Contact Number <span> <input type="text" placeholder="Phone" name="txtphone" value="" /> </span> </p>
                        </div>
                          <div class="column dt-sc-one-third first">
                            <p><span class="auto-style2">Company Name <span> <input type="text" placeholder="Company Name" name="txtcomp" value="" /> </span> </p>
                        </div>
                        <div class="column dt-sc-one-third">
                            <p><span class="auto-style2">No Of Employees <span> <input type="number" placeholder="No Of Employees" name="txtemp" value="" /> </span> </p>
                        </div>
                        <div class="column dt-sc-one-third">
                            <p><span class="auto-style2">Move In Date <span> <input type="date" placeholder="Move In Date" name="txtmove" value="" /> </span> </p>
                        </div>


                        <p> <span class="auto-style2">Please describe below what kind of office you are looking for,we will reply to your query on the same day.<textarea placeholder="Message*" name="txtmessage" maxlength "750"  required ></textarea> </p>
                        <p> <input type="submit" value="Send Message" name="submit" /> </p>
                    </form>
                    <div id="ajax_contact_msg"></div>
                </div>

Update 01/10/15

Hi Guys

I made the changes suggested by Dp and sebastianbrosch. The website is now live again but when i attempt to send the form, it says "the page save failed". Below is the updated php code, the html contact us page file remains the same.


Hi apologies i have pasted the php code, but for some reason, it is not showing up in the post. I will try again.

<?php
if(!$_POST) exit;

$to       = '[email protected]'; 
$name     = $_POST['txtname'];
$email    = $_POST['txtemail'];
$phone    = $_POST['txtphone'];
$comp     = $_POST['txtcomp'];
$emp      = $_POST['txtemp'];
$move     = $_POST['txtmove'];
$comment  = $_POST['txtmessage'];

if(get_magic_quotes_gpc()) { $comment = stripslashes($comment); }


 $subject = 'Office enquiry via domain.com from ' . $name . '.';

 $msg  = "You have been contacted by ".$name."\r\n\n";
 $msg .= "You can contact ".$name." via email, ".$email.".\r\n\n";
 $msg .= "You can call ".$name." on ".$phone.".\r\n\n";
 $msg .= "$name has ".$emp." employees and the company name is ."$comp.".\r\n\n";
 $msg .= $name." would like to move in on ."$move.".\r\n\n";
 $msg .= $comment."\r\n\n";


 $msg .= "---------------------------------------------------------------\r\n";

 if(@mail($to, $subject, $msg, "From: $email\r\nReturn-Path: $email\r\n"))
 {
     echo "<span class='success-msg'>Thanks for Contacting Us, We have received your query and will be in touch soon.</span>";
 }
 else
 {
     echo "<span class='error-msg'>Sorry your message was not sent, Please try again or contact us via live chat.</span>";
 }
?>

Upvotes: 1

Views: 151

Answers (2)

DpEN
DpEN

Reputation: 4364

Your Code :

$msg  = "You have been contacted by $name.\r\n\n";
$msg .= "$comment\r\n\n";
$msg .= "You can contact $name via email, $email.\r\n\n";
$msg  = "You can call $name on $phone.\r\n\n";
$msg  = "$name has $emp employees and the company name is $comp.\r\n\n";
$msg  = "$name would like to move in on $move.\r\n\n";

Try The Following :

$msg  = "You have been contacted by ".$name."\r\n\n";
$msg .= $comment."\r\n\n";
$msg .= "You can contact ".$name." via email, ".$email.".\r\n\n";
$msg .= "You can call ".$name." on ".$phone.".\r\n\n";
$msg .= "$name has ".$emp." employees and the company name is $comp.".\r\n\n";
$msg .= $name." would like to move in on ."$move.".\r\n\n";

I think you had several string concatenation errors according to what you have explained in your question.

Upvotes: 1

Sebastian Brosch
Sebastian Brosch

Reputation: 43574

There are missing the points in front of the = in the following lines

$msg  = "You can call $name on $phone.\r\n\n";
$msg  = "$name has $emp employees and the company name is $comp.\r\n\n";
$msg  = "$name would like to move in on $move.\r\n\n";

Replace with the following lines

$msg  .= "You can call $name on $phone.\r\n\n";
$msg  .= "$name has $emp employees and the company name is $comp.\r\n\n";
$msg  .= "$name would like to move in on $move.\r\n\n";

Upvotes: 5

Related Questions