1

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 = "receiversemail@somewhere.com";
$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.

Andrea
  • 477
  • 1
  • 9
  • 22
  • Test if the mail is actually sent by using something like `if (mail($r, $s, $m, $h)) echo "mail sent"; else echo "mail NOT sent";` – Sorin Buturugeanu Mar 24 '12 at 21:20
  • Try turning on error reporting and check the return value from your `mail()` call. Also make sure you have set up `smtp` correctly in your `php.ini` file. – Cyclonecode Mar 24 '12 at 21:21
  • Could be various of reasons, probably mail server is not set. – dotoree Mar 24 '12 at 21:21
  • Could use Gmail http://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page – dotoree Mar 24 '12 at 21:22
  • @Sorin Buturugeanu: The echo page says "Mail Sent." I put the "if" statement you provided under the 'mail(($recipient, $subject, $msg, $mailheaders);' statement. Thanks for your reply. – Andrea Mar 24 '12 at 22:01
  • then check your spam folder. some mails sent via `mail` get flagged as spam. try sending to another email address (different provider). – Sorin Buturugeanu Mar 25 '12 at 13:57

4 Answers4

1

Are you assigning the $_GET[] values from the form to variables prior to this portion of your code?

$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 = "abosiger@embarqmail.com";
$subject = "from PI Website";

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

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

If not, you need to either initialize your $_GET[] values to individual variables:

$txtfname = $_GET['textfname'];

for each variable sent through get. Or you can access them directly from the $_GET array through the following syntax:

$msg = "Sender Name:\t" . $_GET['txtfname'] . "\n";

Let me know if this helps.

kjones
  • 1,339
  • 1
  • 13
  • 28
  • I didn't get info through email – Andrea Mar 24 '12 at 22:14
  • I do have "$txtfname = $_GET['txtfname'];" at the beginning of the script for each variable that needs to be sent. – Andrea Mar 24 '12 at 22:22
  • As @Krister Andersson stated above, I think you may need to check the smtp settings in your php.ini. – kjones Mar 24 '12 at 22:54
  • 1
    I would also place your call to the mail() function in an if/else block: `if (mail($recipient, $subject, $msg, $mailheaders)) { echo 'Mail Sent.'; } else { echo 'Sending failed.'; }`. If this code prints 'Mail Sent' and you still don't receive the email, or prints 'Sending failed' then you should try enabling error reporting and move forward from there. – kjones Mar 24 '12 at 22:55
0

if message sent and no mails is receieved, this authenticating issues from your domain ... your script might works fine The two main ways to do this is either using PHPMail() or SMTP. PHPMail() is open and used by trojans and viruses. Most clients have infected files which just send mails using PHPMail(), because it doesn't authenticate. It doesn't check if the email being sent is actually coming from the domain and this puts a lot of strain on the mail server, making legitimate mails wait in queue for a long time.

If you already have a script using PHPMail() function it is very simple to change it to SMTP, you just need to change like 5 lines of your code and add an email address and password (already created in cpanel) into the code, and it will send emails just fine.

if ($_POST['submit']){



 $from = "slick@meetslick.com"; //enter your email address
 $to = "slickbozz@gmail.com"; //enter the email address of the contact your sending to
 $subject = "Contact Form"; // subject of your email

$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);

$text = ''; // text versions of email.
$html = "<html><body>Name: $name <br> Email: $email <br>Message: $message <br></body></html>"; // html versions of email.

$crlf = "\n";

$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);

//do not ever try to call these lines in reverse order
$body = $mime->get();
$headers = $mime->headers($headers);

 $host = "localhost"; // all scripts must use localhost
 $username = "support@meetslick.com"; //  your email address (same as webmail username)
 $password = " here "; // your password (same as webmail password)

$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,
'username' => $username,'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
}
else {
echo("<p>Message successfully sent!</p>");
// header("Location: http://www.meetslick.com/");
}
  }

I hope this will be helpful to someone one day.

0

The problem probably comes from a bad configuration of the mail function. You have to configure it properly.

Also, you should provide an email in the "From" header.

haltabush
  • 4,508
  • 2
  • 24
  • 41
0
<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?> 

change it like this.

guybennet
  • 683
  • 1
  • 9
  • 25
  • I tried this, putting my email address in the "to" field. I got the new page "Mail Sent" but I didn't receive the email with the info. – Andrea Mar 24 '12 at 21:54
  • can you get the info from the form? please try to echo your values. echo $_get["txtfname"]; – guybennet Mar 24 '12 at 22:03
  • 1
    please check here, it will help you. http://www.html-form-guide.com/contact-form/php-email-contact-form.html – guybennet Mar 24 '12 at 22:18
  • I ended up using the link you provided (html-form-guide.com/contact-form/php-email-contact-form.html ) to set up the form. Works great. Thanks. – Andrea Mar 25 '12 at 16:55
  • ohh nice. what was the problem? – guybennet Mar 25 '12 at 17:18
  • Not sure what the problem was with the form/script I was using in the post. I went to the link you provided, downloaded the files, edited it to fit my form, tested, and everything went through with great success. You have to love when that happens! Thanks again. – Andrea Mar 25 '12 at 17:41