Contact form with php [DOESN'T SEND]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saucez
Forum Newbie
Posts: 14
Joined: Wed Nov 26, 2008 11:49 pm

Contact form with php [DOESN'T SEND]

Post by saucez »

This is an email script for a contact form[it has the form on one page and the code on the next]

1st Page[its a added to the page by a database]

Code: Select all

EMAIL DOESN't WORK at the moment sorry!
<form id="Send" name="Send" method="post" action="send.php">
  <table width="176" border="0" align="center" cellpadding="3" cellspacing="0">
    <tr>
      <td colspan="2"><h1>Contact Us</h1></td>
    </tr>
    <tr>
      <td width="70">Name:</td>
      <td width="106"><label>
        <input type="text" name="name" id="name" tabindex="1" />
      </label></td>
    </tr>
    <tr>
      <td>Email:</td>
      <td><label>
        <input type="text" name="email" id="email" tabindex="2" />
      </label></td>
    </tr>
    <tr>
      <td>Subject:</td>
      <td><select name="subject" id="subject">
        <option value="none~">Please Select a Subject</option>
        <option value="General">General</option>
        <option value="Website Quote">Website Quote</option>
        <option value="Question?">Question?</option>
        <option value="Broken Link?">Broken Link?</option>
        <option value="Bug/Error">Bug/Error</option>
        <option value="Other">Other</option>
      </select>
      </td>
    </tr>
    <tr>
      <td>Message:</td>
      <td><textarea name="message" rows="3" wrap="virtual" id="textfield"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input type="submit" name="button" id="button" value="Send Email" tabindex="3" />
      </label></td>
    </tr>
  </table>
</form>
2nd page[send.php]:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
 
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="i-style.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<div align="center">
  <?php 
// check for a valid enmail and make sure its not spam
function spamcheck($formfield) 
{
$formfield = filter_var($formfield, FILTER_SANITIZE_EMAIL);
  if(filter_var($formfield, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
}
 
if (isset($_POST["email"]))
{
$mailcheck = spamcheck($_REQUEST['email']);
    if ($mailcheck==FALSE)
        {
        echo "<h2>Invalid input, <a href='i-page.php?pagelink=4'>go back</a></h2>";
        }
    else 
        {
        $email = $_POST["email"];
        $subject = $_POST["subject"];
        $message = $_POST["message"];       
        $name = $_POST["name"];
        
        mail("james@think-designs.net", "Subject: $subject", $message, "From: $email" );
    
        echo '<h2><b>Thank you ' . $name . ' Your email has been sent!</b></h2>';
        }
}
else 
{
    echo "Sorry you didn't completly fill out the email form, please go back and fill it out<br /><a href='i-page.php?pagelink=4'> << Go Back</a>";
 
}
?>
</div>
</body>
</html>
 
THE PROBLEM:

It doesn't send on the send.php page, please help =]
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Contact form with php [DOESN'T SEND]

Post by it2051229 »

try this on your send.php

Code: Select all

 
if(isset($_POST["button"]))
{
     $email = $_POST["email"];
 
     print $email;
}
 
saucez
Forum Newbie
Posts: 14
Joined: Wed Nov 26, 2008 11:49 pm

Re: Contact form with php [DOESN'T SEND]

Post by saucez »

where do u i put it :S im a newb at php

please post the whole of send.php with the code in it and put comments if possiable =]]
plz

thanks xD
saucez
Forum Newbie
Posts: 14
Joined: Wed Nov 26, 2008 11:49 pm

Re: Contact form with php [DOESN'T SEND]

Post by saucez »

btw i will explain the error abit better:

i press send, and of coasre it says i have sent it, but when i check my inbox the email will not come for some reason
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Contact form with php [DOESN'T SEND]

Post by aceconcepts »

Try setting some headers
saucez
Forum Newbie
Posts: 14
Joined: Wed Nov 26, 2008 11:49 pm

Re: Contact form with php [DOESN'T SEND]

Post by saucez »

I have just added some headers, please help, im pulling my hair out lol. i need to get this finished =]

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
 
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="i-style.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<div align="center">
  <?php 
// check for a valid enmail and make sure its not spam
function spamcheck($formfield) 
{
$formfield = filter_var($formfield, FILTER_SANITIZE_EMAIL);
  if(filter_var($formfield, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
}
 
if (isset($_POST["email"]))
{
$mailcheck = spamcheck($_REQUEST['email']);
    if ($mailcheck==FALSE)
        {
        echo "<h2>Invalid input, <a href='i-page.php?pagelink=4'>go back</a></h2>";
        }
    else 
        {
        $to = 'james@think-designs.net';
        $subject = $_POST["subject"];
        $message = $_POST["message"];       
        $name = $_POST["name"];
        $headers = "From: $email";
        
        mail($to, $subject, $message, $headers);
    
        echo '<h2><b>Thank you ' . $name . ' Your email has been sent!</b></h2>';
        }
}
else 
{
    echo "Sorry you didn't completly fill out the email form, please go back and fill it out<br /><a href='i-page.php?pagelink=4'> << Go Back</a>";
 
}
?>
</div>
</body>
</html>
 
please some1 give a good look over it and tell me why it will not send. Like it passes all the If statments and says it has been sent, here if you want to check it out go to http://think-designs.net/ and then press the contact us page and fill it out, it says it has sent, but nothing happens, it used to qwork and then i changed it, but i must of changed somthing i shouldn't of and then stuffed it up
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Contact form with php [DOESN'T SEND]

Post by greyhoundcode »

Have you checked your spam folder?
saucez
Forum Newbie
Posts: 14
Joined: Wed Nov 26, 2008 11:49 pm

Re: Contact form with php [DOESN'T SEND]

Post by saucez »

LOL ur right lol, it was in my google apps spam folder, but i use outlook so it didn't get in that spam folder lol.

Just wondering how do u make this email script not appear as spam???
saucez
Forum Newbie
Posts: 14
Joined: Wed Nov 26, 2008 11:49 pm

Re: Contact form with php [DOESN'T SEND]

Post by saucez »

dw i got it, thanks guys
Post Reply