Confirmation email in PHP Form

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
necee8483
Forum Newbie
Posts: 20
Joined: Mon Nov 03, 2008 3:09 pm

Confirmation email in PHP Form

Post by necee8483 »

okay so i am new to php. I learn quickly. I have a form set up that enters information into a database I have set up through mysql phpadmin. Everything works fine. What I am trying to figure out is the email function for php. I have found the format to set up the email in php. But I am missing something and I am not sure what. What I am looking to do it set it up so that when the user(customer/agent) fills out the form that a automated email goes out to the email address entered into the database/email text box. I will attach the code that I have already written if someone could please point me in the right direction i can duplicate through my website in appropriate areas. Also the code I have written is just in a test page that is not connected to my database so that I do not mess up what I have already functioning.

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>
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<form id="form1" name="form1" method="post" action="http://www.startlogic.com/scripts/formemail.bml">
  <table width="200" border="1" align="center">
    <tr>
      <td>Conversations 10 points:</td>
      <td><span id="Conversations">
      <label>
      <input name="conversations" type="text" id="conversations" value="0" size="3" maxlength="3" />
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
    </tr>
    <tr>
      <td>Email Address:</td>
      <td><span id="emailaddress">
      <label>
      <input type="text" name=["$emailtest"] id=["$emailtest"] />
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
    </tr>
    <tr>
      <td>Recruits 100 points:</td>
      <td><span id="Recruits">
      <label>
      <input name="recruits" type="text" id="recruits" value="0" size="3" maxlength="3" />
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input type="submit" name="submit" id="submit" value="Submit" />
      </label></td>
    </tr>
  </table>
  <p>&nbsp; </p>
  <p>&nbsp;</p>
  <?php
 
//Check whether the submission is made
if(isset($hidSubmit)){
 
//Declarate the necessary variables
$mail_to=$txtEmailto; $txtEmailto='$emailtest';
$mail_from=$txtEmailfrm; $txtEmailfrm='deniseadkins83@gmail.com';
$mail_sub=$txtSub; $txtSub='Test';
$mail_mesg=$txtMsg; $txtMsg='this is a test and is only a test of my sweet php ability';
 
//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
echo "<span class='red'>E-mail has been sent successfully from $mail_sub to $mail_to</span>";
else
echo "<span class='red'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
?>
 
  <input name="thankyou_url" type="hidden" id="thankyou_url" value="http://www.spartanwisdom.com" />
</form>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("Recruits", "integer");
var sprytextfield2 = new Spry.Widget.ValidationTextField("Conversations", "integer");
var sprytextfield3 = new Spry.Widget.ValidationTextField("emailaddress", "email");
//-->
</script>
</body>
</html>
 
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Confirmation email in PHP Form

Post by infolock »

First, not sure why you are doing something like name=["$emailtest"] id=["$emailtest"] />. This should just be name="emailtest" id="emailtest" as you are not echoing any PHP variables out.

Second, you are calling global variables, ie $hidSubmit, $txtEmailto, etc. If you are using PHP 5 (i think even 4.4+ is this way too), globals are disabled by default, so you must use superglobal methods, ie $_POST['hidSubmit'], $_POST['txtEmailto'], etc.

Finally, I'm pretty sure your /r/n should be \r\n ;)

Hope this helps.
necee8483
Forum Newbie
Posts: 20
Joined: Mon Nov 03, 2008 3:09 pm

Re: Confirmation email in PHP Form

Post by necee8483 »

Thank you so much. I knew the codewas wrong I just wasn't sure where.. I will make the changes and see how it comes out. and let you know. Thanks so so so so much.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: Confirmation email in PHP Form

Post by infolock »

No problem, glad to help (=
Post Reply