Results 1 to 12 of 12
  1. #1
    Join Date
    Oct 2007
    Posts
    5

    Help with PHP contact script

    Hello I was installing a php contact script everything seems to be working fine except for the fact it is not sending an email to me. Here is the basic code. I was told I just needed to change the "[email protected]" into my email address and it should work. I must be missing other stuff.

    I would appreciate it if someone could take a quick look and guide me if you have time.

    <?php
    if ($_POST['yourname'] != "" && $_POST['youremail'] && $_POST['yourphone'] && $_POST['yourcountry'] && $_POST['smallsubject'] && $_POST['comment'] ) {
    $subject="Form posted from my site ";
    $ip=$_SERVER["REMOTE_ADDR"];
    $host = $ip;
    $mon=date(m);
    $day=date(j);
    $year=date(y);
    $hour=date(g);
    $min=date(i);
    $sec=date(s);
    $hour=$hour-2;
    if($hour<=0) { $hour+=12; }
    $ts = "$hour:$min:$sec on $day/$mon/$year";


    $to="[email protected]";

    $body="

    Your Name = $yourname

    Your Email = $youremail

    Your Phone = $yourphone

    Your Country = $yourcountry

    Your Site = $yoursite

    Small Subject = $smallsubject

    Comment = $comment


    Host: $host
    Time: $ts";

    $email = "From: Form <$to>";
    mail($to, $subject, $body, $email);
    ?>

    <html>
    <head>
    <title>Email Sent</title>
    </head>
    <body bgcolor="#ffffff" text="#666666">

    <p>&nbsp;</p>
    <center>
    <table border="1" cellpadding="3" cellspacing="0" width="400" bordercolor="#919191" bgcolor="#E6E6E6">
    <tr>
    <td width="100%">
    <p><center><b><font color="#000000">Email was successfully sent to: Admin And He Will Contact With You As Soon As Possible</font></b></center>

    </td>
    </tr>
    </table>

    </body>
    </html>

    <?php
    } else {
    ?>

    <html>
    <head>
    <title>Contact email error</title>
    </head>

    <body bgcolor="#ffffff" text="#666666">
    <p><center>
    <table border="1" cellpadding="3" cellspacing="0" width="400" bordercolor="#919191" bgcolor="#E6E6E6">
    <tr>
    <td width="100%">
    <center>
    <b>There was an error with processing the email.</b><br>
    <p>
    <font color="#FF0000">Errors where:</font><br>
    <?php
    If (!$_POST['yourname'])
    echo "Your Name field is empty<br>";

    If (!$_POST['youremail'])
    echo "Your Email field is empty<br>";

    If (!$_POST['yourphone'])
    echo "Your Phone field is empty<br>";

    If (!$_POST['yourcountry'])
    echo "Your Country field is empty<br>";

    If (!$_POST['smallsubject'])
    echo "Small Subject field is empty<br>";

    If (!$_POST['comment'])
    echo "Comment field is empty<br>";

    ?>
    <p>
    Email message wasn't sent

    </td>
    </tr>
    </table>
    </body>
    </html>

    <?php
    }
    ?>

  2. #2
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    From is spelled wrong in Email variable.

    Are there any errors?

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  3. #3
    Join Date
    Oct 2007
    Posts
    5
    There are no errors. I fixed the from but it is still not sending email.

    Any more ideas?

    Thanks
    tj

  4. #4
    Join Date
    Mar 2004
    Posts
    1,301
    email server is down perhaps? or disabled?

  5. #5
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    Check your spam box.

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  6. #6
    Join Date
    Oct 2006
    Posts
    76
    If you're using an SMTP server that is not localhost / not on your webhosts's network, and this is shared hosting, it may well be blocked by the firewall rules on your web server.

  7. #7
    Join Date
    Dec 2007
    Location
    Lebanon
    Posts
    413
    send to other than gmail hotmail, yahoo and know mail servers try to send to yourself

  8. #8
    Join Date
    Oct 2002
    Location
    State of Disbelief
    Posts
    22,948
    Umm, shouldn't all of these have ";" after them (syntax error)?
    $body=";
    Your Name = $yourname;
    Your Email = $youremail;
    Your Phone = $yourphone;
    Your Country = $yourcountry;
    Your Site = $yoursite;
    Small Subject = $smallsubject;
    Comment = $comment;
    Host: $host;
    Having problems, or maybe questions about WHT? Head over to the help desk!

  9. #9
    Join Date
    Dec 2007
    Location
    Lebanon
    Posts
    413
    no I think he's concatenating all in body

  10. #10
    Join Date
    Feb 2007
    Posts
    40
    It seems like your mail server is not working. Have you checked that already?

  11. #11
    Join Date
    Oct 2005
    Location
    Six Degrees From You
    Posts
    1,075
    Have you turned error reporting on? If so what does it say?

    Paul

  12. #12
    Join Date
    Sep 2004
    Location
    US
    Posts
    29
    You will receive the email ONLY when this IF condition is met. Try inserting an
    echo "anything";
    before the mail function. If the text is displayed means something is wrong with the email delivery OTHERWISE it would mean the IF condition is not TRUE.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •