Hybridmoments82 Posted July 27, 2009 Share Posted July 27, 2009 Hello all! I'm trying to develop a simple PHP "credit card authorization" form so that when lawyers need to use the practice's credit card, they can fill this form out so I can manage the info a little easier. I used various tutorials/dreamweaver and came up with the below code as my php document (email has been changed to protect the identity of the idiot). Needless to say, it won't send the info via email and the "error" page always pops up: <?php if(isset($_POST['submit'])) { $to = "user@domain.com"; $subject = "Authorization Form"; $category1 = $_POST['category1']; $description1 = $_POST['description1']; $amount1 = $_POST['amount1']; $category2 = $_POST['category2']; $description2 = $_POST['description2']; $amount2 = $_POST['amount2']; $category3 = $_POST['category3']; $description3 = $_POST['description3']; $amount3 = $_POST['amount3']; $category4 = $_POST['category4']; $description4 = $_POST['description4']; $amount4 = $_POST['amount4']; $category5 = $_POST['category5']; $description5 = $_POST['description5']; $amount5 = $_POST['amount5']; $category6 = $_POST['category6']; $description6 = $_POST['description6']; $amount3 = $_POST['amount6']; $category7 = $_POST['category7']; $description7 = $_POST['description7']; $amount7 = $_POST['amount7']; echo "Data has been submitted to $to!"; } else { echo "Error: Contact Network Administrator for assistance."; } ?> Here's the HTML: <style type="text/css"> <!-- body { background-image: url(background.jpg); } .style2 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #FFFFFF; } .style3 {color: #FFFFFF} .style6 {font-size: 24px} .style7 {color: #FFFFFF; font-family: Arial, Helvetica, sans-serif;} --> </style> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <br> <form method="POST" action="mailer.php"> <div align="left"> <p align="center"><span class="style7"><span class="style6">Credit Card Authorization Request</span></span><span class="style2"><br> </span><br> </p> </div> <table width="928" height="24" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="658"><span class="style2">Attorney / Secretary: <input type="text" name="attorney" size="25" /> / <input type="text" name="secretary" size="25" /> </span></td> <td width="270"><div align="right"><span class="style2">Date: <input type="text" name="date" size="30" /> </span></div></td> </tr> </table> <table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> </td> </tr> </table> <table width="931" height="364" border="0" align="center" cellpadding="0" cellspacing="4" bgcolor="#1C1511"> <tr> <td width="128" bgcolor="#000000"><div align="center" class="style2">Category</div></td> <td width="540" bgcolor="#000000"><div align="center"><span class="style2">Description</span></div></td> <td width="139" bgcolor="#000000"><div align="center"><span class="style2">Amount</span></div></td> <td width="124" bgcolor="#000000"><div align="center"><span class="style2">Firm/Case#</span></div></td> </tr> <tr> <td height="41"><select size="1" name="category1"> <option>Select Category</option> <option>Lodging</option> <option>Airfare</option> <option>Car Rental/Taxi</option> <option>Seminar</option> </select></td> <td><input type="text" name="description1" size="90" /></td> <td><input type="text" name="amount1" size="19" /></td> <td><input type="text" name="firm1" size="19" /></td> </tr> <tr> <td height="36"><select size="1" name="category2"> <option>Select Category</option> <option>Lodging</option> <option>Airfare</option> <option>Car Rental/Taxi</option> <option>Seminar</option> </select></td> <td><input type="text" name="description2" size="90" /></td> <td><input type="text" name="amount2" size="19" /></td> <td><input type="text" name="firm2" size="19" /></td> </tr> <tr> <td><select size="1" name="category3"> <option>Select Category</option> <option>Lodging</option> <option>Airfare</option> <option>Car Rental/Taxi</option> <option>Seminar</option> </select></td> <td><input type="text" name="description3" size="90" /></td> <td><input type="text" name="amount3" size="19" /></td> <td><input type="text" name="firm3" size="19" /></td> </tr> <tr> <td><select size="1" name="category4"> <option>Select Category</option> <option>Lodging</option> <option>Airfare</option> <option>Car Rental/Taxi</option> <option>Seminar</option> </select></td> <td><input type="text" name="description4" size="90" /></td> <td><input type="text" name="amount4" size="19" /></td> <td><input type="text" name="firm4" size="19" /></td> </tr> <tr> <td><select size="1" name="category5"> <option>Select Category</option> <option>Lodging</option> <option>Airfare</option> <option>Car Rental/Taxi</option> <option>Seminar</option> </select></td> <td><input type="text" name="description5" size="90" /></td> <td><input type="text" name="amount5" size="19" /></td> <td><input type="text" name="firm5" size="19" /></td> </tr> <tr> <td><select size="1" name="category6"> <option>Select Category</option> <option>Lodging</option> <option>Airfare</option> <option>Car Rental/Taxi</option> <option>Seminar</option> </select></td> <td><input type="text" name="description6" size="90" /></td> <td><input type="text" name="amount6" size="19" /></td> <td><input type="text" name="firm6" size="19" /></td> </tr> <tr> <td><select size="1" name="category7"> <option>Select Category</option> <option>Lodging</option> <option>Airfare</option> <option>Car Rental/Taxi</option> <option>Seminar</option> </select></td> <td><input type="text" name="description7" size="90" /></td> <td><input type="text" name="amount7" size="19" /></td> <td><input type="text" name="firm7" size="19" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td><div align="center"> <input type="submit" value="Send" /> </div></td> </tr> </table> <br> <br> <br> <br> </form> The site's host is running Linux and the latest version of PHP, so obviously the problem is with my script. I have a feeling the answer to this issue is incredibly simple, but this is my first plunge into PHP, and hopefully I'll learn something tonight. Thanks!! Quote Link to comment Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 your condition checks for a submitted variable named "submit". you have: <input type="submit" value="Send" /> you didn't actually name it "submit" it should be <input type="submit" value="Send" name="submit" /> Also, there's nothing in your condition that actually mails anything to anybody. Quote Link to comment Share on other sites More sharing options...
Hybridmoments82 Posted July 28, 2009 Author Share Posted July 28, 2009 Thank you for your response. How do I specify a conditional statement that would send the form via email? It seems as if my php.ini file is set to SMTP - is there any further ini settings I need to add? This was preconfigured by my host (GoDaddy): register_globals = off allow_url_fopen = off expose_php = Off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 SMTP = relay-hosting.secureserver.net url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" [Zend] zend_extension=/usr/local/zo/ZendExtensionManager.so zend_extension=/usr/local/zo/4_3/ZendOptimizer.so Quote Link to comment Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 Are you asking how you would email the submitted form info to somewhere? You already have a condition setup to check if form info was posted. You also have posted vars assigned to more readable vars. All you need to do is put the mail function in there and you're set. Quote Link to comment Share on other sites More sharing options...
Hybridmoments82 Posted July 28, 2009 Author Share Posted July 28, 2009 Thanks for your post. Lest to say, I'm a noob and that link you posted looks like a great resource! I'm still somewhat unclear though. Do I have to edit the mail() function to suit my form in any way or do I just cut and paste the code into the ini? EDIT: Or do I have to edit the mail() function to suit my mailer.php? Quote Link to comment Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 first code you posted: <?php if(isset($_POST['submit'])) { $to = "user@domain.com"; $subject = "Authorization Form"; $category1 = $_POST['category1']; $description1 = $_POST['description1']; $amount1 = $_POST['amount1']; $category2 = $_POST['category2']; $description2 = $_POST['description2']; $amount2 = $_POST['amount2']; $category3 = $_POST['category3']; $description3 = $_POST['description3']; $amount3 = $_POST['amount3']; $category4 = $_POST['category4']; $description4 = $_POST['description4']; $amount4 = $_POST['amount4']; $category5 = $_POST['category5']; $description5 = $_POST['description5']; $amount5 = $_POST['amount5']; $category6 = $_POST['category6']; $description6 = $_POST['description6']; $amount3 = $_POST['amount6']; $category7 = $_POST['category7']; $description7 = $_POST['description7']; $amount7 = $_POST['amount7']; echo "Data has been submitted to $to!"; // pre-populate these vars with whatever you want. Hopefully names of vars are self-explanatory. mail($to,$subject,$content); } else { echo "Error: Contact Network Administrator for assistance."; } ?> Quote Link to comment Share on other sites More sharing options...
Hybridmoments82 Posted July 28, 2009 Author Share Posted July 28, 2009 That's what I gathered I was supposed to do, but when I added the vars, I get this error message: Warning: mail() expects at most 5 parameters, 30 given in mailer.php on line 34 Data has been submitted to username@domain.com! Here's my new mailer.php: <?php if(isset($_POST['submit'])) { $to = "hybridmoments82@gmail.com"; $subject = "Credit Card Auth Form"; $category1 = $_POST['category1']; $description1 = $_POST['description1']; $amount1 = $_POST['amount1']; $firm1 = $_POST['firm1']; $category2 = $_POST['category2']; $description2 = $_POST['description2']; $amount2 = $_POST['amount2']; $firm2 = $_POST['firm2']; $category3 = $_POST['category3']; $description3 = $_POST['description3']; $amount3 = $_POST['amount3']; $firm3 = $_POST['firm3']; $category4 = $_POST['category4']; $description4 = $_POST['description4']; $amount4 = $_POST['amount4']; $firm4 = $_POST['firm4']; $category5 = $_POST['category5']; $description5 = $_POST['description5']; $amount5 = $_POST['amount5']; $firm5 = $_POST['firm5']; $category6 = $_POST['category6']; $description6 = $_POST['description6']; $amount6 = $_POST['amount6']; $category7 = $_POST['category7']; $description7 = $_POST['description7']; $amount7 = $_POST['amount7']; $firm7 = $_POST['firm7']; mail($to,$subject,$category1,$description1,$amount1,$firm1,$category2,$description2,$amount2,$firm2,$category3,$description3,$amount3,$firm3,$category4,$description4,$amount4,$firm4,$category5,$description5,$amount5,$firm5,$category6,$description6,$amount6,$firm6,$category7,$description7,$amount7,$firm7); echo "Data has been submitted to $to!"; } else { echo "Credit Card Authorization Form has been submitted."; } ?> I feel like I'm getting closer! Then again, that could just be indigestion. Quote Link to comment Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 assign all of the variables to $subject Quote Link to comment Share on other sites More sharing options...
Hybridmoments82 Posted July 28, 2009 Author Share Posted July 28, 2009 I ran into problems with specifying a lot more than the capped 6 parameters in mail(), but I found a fix. The code after my $_POST codes now looks like this: $embody = "$category1,$description1,$amount1,$firm1,$category2,$description2,$amount2,$firm2,$category3,$description3,$amount3,$firm3,$category4,$description4,$amount4,$firm4,$category5,$description5,$amount5,$firm5,$category6,$description6,$amount6,$firm6,$category7,$description7,$amount7,$firm7"; mail($to,$subject,$embody); Now everything sends perfectly, thanks to the chivalrous few who held a noob's hand through his first PHP experience. The only thing now is that when the data is sent via email, it's a jarbled mess. Can anyone point me in the direction of a good php-based email formatting tutorial? Quote Link to comment Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 I ran into problems with specifying a lot more than the capped 6 parameters in mail(), but I found a fix. The code after my $_POST codes now looks like this: $embody = "$category1,$description1,$amount1,$firm1,$category2,$description2,$amount2,$firm2,$category3,$description3,$amount3,$firm3,$category4,$description4,$amount4,$firm4,$category5,$description5,$amount5,$firm5,$category6,$description6,$amount6,$firm6,$category7,$description7,$amount7,$firm7"; mail($to,$subject,$embody); right...dunno why you had to go searching for that, considering that's what I said to do... assign all of the variables to $subject Now everything sends perfectly, thanks to the chivalrous few who held a noob's hand through his first PHP experience. The only thing now is that when the data is sent via email, it's a jarbled mess. Can anyone point me in the direction of a good php-based email formatting tutorial? I don't think you'll really find something like that, per se... formatting is pretty much a unique thing, based on your own tastes. here is an example of putting each one on an individual line: $embody = <<<MBODY $category1 \n $description1 \n $amount1 \n $firm1 \n $category2 \n $description2 \n $amount2 \n $firm2 \n $category3 \n $description3 \n $amount3 \n $firm3 \n $category4 \n $description4 \n $amount4 \n $firm4 \n $category5 \n $description5 \n $amount5 \n $firm5 \n $category6 \n $description6 \n $amount6 \n $firm6 \n $category7 \n $description7 \n $amount7 \n $firm7 \n MBODY; Quote Link to comment Share on other sites More sharing options...
Hybridmoments82 Posted July 28, 2009 Author Share Posted July 28, 2009 Once again, thank you, Crayon Violent for all your help. While "assign all of the variables to $subject" may mean something to an experienced PHP user, it actually means very little to someone who's "winging it", if you will. As stated, I'm brand new to PHP, and this experience coding my little email form has been one massive educational experience, solely thanks to your support. Your code worked in spades. I modified it to suit my needs and it works perfectly. You have successfully enlightened the unenlightened in basic PHP coding! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.