Can anybody assist with a php mail form script? Its hurting!

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
smallville06
Forum Newbie
Posts: 3
Joined: Tue Jul 04, 2006 4:33 am

Can anybody assist with a php mail form script? Its hurting!

Post by smallville06 »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


The following is my contact.php file code:  In summary the php script is simply to validate that some details have been entered into the form and then it's supposed to grab the globals and dump them i think.

What needs to be included in the script for the form to work properly?  It's really bugging me out.  And also if anybody has any idea how to code php how would i validate the form data if it had drop down boxes??

Other simple validations i can do i just havent written them yet..

Any help would be much appreciated.

Code: Select all

<?php
include $_SERVER['DOCUMENT_ROOT'].'/layout.php';

switch($_REQUEST['req']){
case "process":
   myheader("Become a Member: Step 2");

   // Validate all required fields were posted
   if(!$_POST['first_name'] || 
      !$_POST['last_name'] ||
      !$_POST['email_address'] || 
      !$_POST['email_address2'] ||
      !$_POST['username'] || 
      !$_POST['password'] || 
      !$_POST['password2'] || 
      !$_POST['bio']){
         
         $errors .= "<strong>Form Input Errors:".
                    "</strong>\n\n";
         $error = true;
         
         if(!$_POST['first_name']){
            $errors .= "Missing First Name\n";
         }
         
         if(!$_POST['last_name']){
            $errors .= "Missing Last Name\n";
         }
        
         if(!$_POST['email_address']){
            $errors .= "Missing Email Address\n";
            $email_error = true;
         }
         
         if(!$_POST['email_address2']){
            $errors .= "Missing Email Address Verification\n";
            $email_error = true;
         }
         
         if(!$_POST['username']){
            $errors .= "Missing Username\n";
         }
         
         if(!$_POST['password']){
            $errors .= "Missing Password\n";
            $password_error = true;
         }
         
         if(!$_POST['password2']){
            $errors .= "Missing Password Verification\n";
            $password_error = true;
         }
         
         if(!$_POST['bio']){
            $errors .= "Missing Information About Yourself\n";
         }
   }
   

   }
   
   // If $error is TRUE, then include the singup form
   // and display the errors we found.
   
   if($error == true){
      $errors = nl2br($errors);
      include $_SERVER['DOCUMENT_ROOT'].
              '/html/forms/membership_signup.html';
      footer();
      exit();
   }
   
   $mailer = &new Email;                 
   // Email user
   $mailer->ToMail = $_POST['email_address'];
   $mailer->FromMail = "admin@test.com";
   $mailer->FromName = "My PHP Site Administrator";
   $mailer->Subject = "Your Membership at My PHP Site";
   $mailer->Message = "Dear $_POST[first_name],\n".
                      "Thanks for joining our website! We".
                      " welcome you and look forward to".
                      " your participation.\n\n".
                      "Below you will find the ".
                      "information required to ".
                      "Login to our website!\n\n".
                      "First, you will need to verify".
                      " your email address ".
                      "by clicking on this ".
                      "hyperlink:\n$verify_url\nand ".
                      "following the directions in your ".
                      " web browser.\n\n".
                      "=====================\n".
                      "Username: $_POST[username]\n".
                      "Password: $_POST[password]\n".
                      "UserID: $userid\n".
                      "Email Address: ".
                      "$_POST[email_address]\n".
                      "=====================\n\n".
                      "Thank you,\n".
                      "My PHP Site Administrator\n".
                      "http://$_SERVER[SERVER_NAME]\n";      
   $mailer->SendMail();
                       
   // Email Admin
   $mailer->ToMail = "peter@bla.com";
   $mailer->FromMail = "admin@test.com";
   $mailer->FromName = "My PHP Site Administrator";
   $mailer->Subject = "New Member at My PHP Site [$userid]";
   $mailer->Message = "Hi,\n\n".
                      "A new member has just signed up ".
                      "at My PHP Site! Here's their ".
                      " information:\n\n".
                      "=====================\n".
                      "First Name: $_POST[first_name]\n". 
                      "Last Name: $_POST[last_name]\n".
                      "Email Address: ".
                      "$_POST[email_address]\n".
                      "UserID: $userid\n".
                      "=====================\n\n".
                      "Thank you,\n".
                      "My PHP Site Administrator\n".
                      "http://$_SERVER[SERVER_NAME]\n";      
   $mailer->SendMail();
   // Display Success Message
   echo '<p align="center"><font size="4" '.
        'face="Verdana, Arial, Helvetica, sans-serif">'.
        '<strong>Your Signup Was Successful!'.
        '</strong></font></p>'.
        '<p align="center"><font size="4" '.
        'face="Verdana, Arial, Helvetica, sans-serif">'.
        'Please check your email for instructions.'.
        '</font></p>';
   // That's it! Done!
break;

case "verify":
   myheader("Verify Information");
   
   // Perform MysQL Query:
   $sql = mysql_result(mysql_query("SELECT COUNT(*)
                       AS vcount FROM members WHERE 
                       id='{$_GET['id']}' AND
                       md5(first_name) = '{$_GET['vcode']}'
                       "),0);
  
   if($sql == 1){
      $update = mysql_query("UPDATE members SET
                            verified='1' WHERE
                            id='{$_GET['id']}'");
      if(!$update){
         echo "Error with MySQL Query: ".mysql_error();
      } else {
         echo '<p align="center"><font size="4" '.
         'face="Verdana, Arial, Helvetica, sans-serif">'.
         '<strong>You Have Been Verified!'.
         '</strong></font></p>';
         include $_SERVER['DOCUMENT_ROOT'].
                 '/html/forms/contact.html';
      }
   } else {
      echo "Sorry, Could not be verified!";
   }
   footer();
break;

   default:
      myheader("Become a Member!");
      include $_SERVER['DOCUMENT_ROOT'].
              '/html/forms/contact.html';
      footer();
   break;
}
?>
And the following is my html output to the browser:

Code: Select all

<link href="../../css/forms.css" rel="stylesheet" type="text/css" />
<p><font color="#66FF00" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong><em>Contact Us </em></strong></font></p>
<?
if($errors){
echo "<p align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#FF0000\">$errors</font></p>\n";
}
?>
<div align="center"></div>
<form method="post" action="/contact.php">
  <table width="50%" border="1" align="center" cellpadding="4" cellspacing="0">
    <tr> 
      <td width="200" align="left" valign="top" nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Company Name </font></td>
      <td width="179" align="left" valign="top"><input name="first_name" type="text" id="first_name" value="<?=$_POST['company_name'];?>"></td>
    </tr>
    <tr> 
      <td width="200" align="left" valign="top" nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Contact Name </font></td>
      <td align="left" valign="top"><input name="last_name" type="text" id="last_name" value="<?=$_POST['contact_name'];?>"></td>
    </tr>
    <tr> 
      <td width="200" align="left" valign="top" nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email Address</font></td>
      <td align="left" valign="top"><input name="email_address" type="text" id="email_address" value="<?=$_POST['email_address'];?>"></td>
    </tr>
    <tr> 
      <td align="left" valign="top" nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Contact Number </font></td>
      <td align="left" valign="top"><input name="email_address2" type="text" id="email_address3" value="<?=$_POST['phone_number'];?>"></td>
    </tr>
    <tr> 
      <td width="200" align="left" valign="top" nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Test</font></td>
      <td align="left" valign="top"><input name="username" type="text" id="username" value="<?=$_POST['test_test'];?>"></td>
    </tr>
    <tr> 
      <td width="200" align="left" valign="top" nowrap>What Is Your Enquiry About? <font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp; </font></td>
      <td align="left" valign="top"><input name="username2" type="text" id="username2" value="<?=$_POST['test_test2'];?>" /></td>
    </tr>
    <tr> 
      <td width="200" align="left" valign="top" nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif">How Did You Find Us? </font></td>
      <td align="left" valign="top"><input name="username3" type="text" id="username3" value="<?=$_POST['test_test3'];?>" /></td>
    </tr>
    <tr> 
      <td width="200" align="left" valign="top" nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Additional Information </font></td>
      <td align="left" valign="top"><textarea name="bio"><?=$_POST['job_details'];?></textarea></td>
    </tr>
    <tr>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top"><input name="req" type="hidden" id="req" value="process">
        <input type="submit" name="Submit" value="Submit Information!"></td>
    </tr>
  </table>
</form>

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

1) Please use PHP and CODE tags where appropriate
2) In what way is it not working?
smallville06
Forum Newbie
Posts: 3
Joined: Tue Jul 04, 2006 4:33 am

Post by smallville06 »

hi mate,

it basically goes straight through to the verification message (in the php code) when i call the script....
smallville06
Forum Newbie
Posts: 3
Joined: Tue Jul 04, 2006 4:33 am

Correction

Post by smallville06 »

Correction,

when the contact.php script is loaded you see the signup successfull message in the header then the form loads and then it goes through the error handling process when the submit button is pressed but nothing happens not matter what data is entered into the html form.
Jixxor
Forum Commoner
Posts: 46
Joined: Wed Jun 07, 2006 5:53 pm
Location: Lakeland, FL

Post by Jixxor »

Is it not sending an e-mail? Or just not doing anything?

Please be more specific on your problem.
Post Reply