Search code examples
phphtmlformsget

PHP get form not receiving email


I'm using a simple web form and some PHP script to send the completed form to my email. When I hit "Submit" I get the PHP text "Thanks, we'll be in touch shortly" but I'm not getting the email with submitted form info. Not sure what's the problem.

from the HTML doc:

<div class='' "letstalk_form">
    <form method="get" action="contact.php" name="contact" id="contact">
        <p>
            <label for="txtfname">Name:</label><input type="text" tabindex="1" name="txtfname" id="txtfname" class="clsTextBox">
        </p>
        <p>
            <label for="txtcompany">Company:</label><input type="text" tabindex="2" name="txtcompany" id="txtcompany" class="clsTextBox">
        </p>
        <p>
            <label for="txtemail">E-mail:</label><input type="text" tabindex="3" name="txtemail" id="txtemail" class="clsTextBox">
        </p>
        <p>
            Message:<textarea name="comments" id="comments" rows="2" cols="20"></textarea>
        </p>
        <p class="submit">
            <input type="submit" value="Submit">
        </p>
    </form>
</div>

and the PHP

$msg = "Sender Name:\t$txtfname\n";
$msg .= "Sender Company:\t$txtcompany\n";
$msg .= "Sender E-mail:\t$txtemail\n";
$msg .= "Comments:\t$comments\n\n";
$recipient = "[email protected]";
$subject = "from PI Website";

$mailheaders = "From: Lets Do Business  <> \n";
$mailheaders .= "Reply-To: $txtemail\n\n";

mail($recipient, $subject, $msg, $mailheaders);

echo "<HTML><HEAD><TITLE>Form Sent!</TITLE></HEAD><BODY>";
echo "<H3 align=center>Thank You, $txtfname</H3>";
echo "<P align=center>Your submission was sent successfully.<br />
I will be contacting you soon.</P>";
echo "</BODY></HTML>";

?> 
</div>

I've used this is the past and worked great. Is there something I overlooked? Thanks for you help!


EDIT: I ended up using the link Turgut Dursun provided (html-form-guide.com/contact-form/php-email-contact-form.html ) to set up the form. Works great. Thanks.


Solution

  • <?php
    $to = "[email protected]";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "[email protected]";
    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
    ?> 
    

    change it like this.