views:

56

answers:

3

I've set up a contact form in the Greet Us page in http://swedsb.com

When I submit the form, it says mail sent successfully. But I'm not getting the mail, checked the spam folder.

I've set a similar form at http://ibsolutions.in. It is working perfectly.

Been breaking my head for the past 4 hours. Here's my contact.php

<?php 

    if(isset($_POST['submit'])) {
    $to = "[email protected]";
    $subject = $_POST['posRegard'];
    $name = $_POST['posName'];
    $email = $_POST['posEmail'];

    if ( preg_match( "/[\r\n]/", $posName ) || preg_match( "/[\r\n]/", $posEmail ) ) {
    header( 'Location: http://swedsb.com/' );
    }

    $message = $_POST['posText'];
    $body = "$name has sent you a greeting. \n E-Mail: $email\nMessage:\n $message";

    mail($to, $subject, $body);
    header( 'Location: http://swedsb.com/' );
 } 
 else {echo "blarg!";}?>
+2  A: 

PHP will always say the mail was send... Checks the path of sendmail in your php.ini file...

Macmade
Yep, all "sent successfully" means is it was put in the outgoing queue for sendmail (or equivalent) to process. You'll need to check the mail daemon on the box to see what happened to it.
Paolo
What should I check the file for? I'm using a shared server at Dreamhost. Is it still possible to check the path of php.ini? Thanks much.
ekalaivan
How do I check the mail daemon?
ekalaivan
Try a phpinfo(), and search for 'mail'
Macmade
A: 
nik
I've fixed the typo. I'm on a shared server and the mail from another website on the same server gets sent perfectly. Should I still try contacting the server admin?
ekalaivan
then there should be no problem on ini or other since it works same for all. Sometime it took some time you can check sending mail at other address try yahoo. the script looks ok
nik
also try adding proper header parameter, reference [php-manual]http://in.php.net/manual/en/function.mail.php.
nik
A: 

I recommend checking the mail server logs. Generally speaking you'll find them somewhere like: /var/log/mail.log.

After locating the log file, run the script and then immediately review the log file and see what happens. Search for the recipient (to address) e-mail to find entry in the log.

Best of luck!

p.s. This script has some serious security problems as-is. Expect spammers will try and trick your code into sending e-mails on their behalf. In particular is important to check any variables which will be used as part of the e-mail headers or content. These values should be sanitized. Look for line feeds, multipart/mixed MIME content boundary markers, and BCC or other headers, and anything else which looks funny. Always send from an explicit e-mail address you provide, do not use the from address the user enters in web form.

nathan