Jump to content

Help! I'm lost in PHP land!


polyxenes

Recommended Posts

Hi - I'm marginally fluent in HTML, much less in CSS and completely ignorant of PHP.

 

I'm making a website for a friend's business that includes a form.  Not being able to figure out any of it, I thought that buying the code from forms4free.com would be the fastest/easiest thing to do.  They've verified my code (HTML and PHP), but it still doesn't work on my end.

 

Tech support at Godaddy, my web host, talked way above my head, but referred me to their help pages.  I think that some part of forms4less' code doesn't match what Godaddy requires, but that's just my guess.

 

I'm hoping that one kind soul here can help me out with this.

 

Following (in order) is Godaddy help page information, form4free's PHP file, then my HTML including form4less code:

 

GODADDY.COM

 

Using the PHP Form-Maiasler

Last Updated: April 3, 2007 11:26 AM

Print This Article

To use the PHP form-mailer, create a Web form in HTML that links to our PHP script and upload it to your hosting account.

 

Remember to specify the email address you want to use with the form-mailer in your account manager. For more information, see Specifying an Email Address for the PHP Form-Mailer.

 

To Use the PHP Form-Mailer

Create your Web form as normal and assign unique names to your form items.

NOTE: Keep in mind that our form-mailer script will sort the names of your form items alphabetically when it composes the email message. This is the order of precedence: uppercase letters, lowercase letters, numbers.

 

For the form action line, enter gdform.php. For example:

<form action="gdform.php" method="post">

Set the form method to "post."

In addtion to the fields you create in your form, there are three special fields that you can use: subject, redirect, and email.

Subject. Controls the subject line in the form email.

 

Redirect. Controls the page that your visitors will see after they submit the form.

 

Email. Controls the return address for the form email.

 

For example:

 

<form action="gdform.php" method="post">
<input type="hidden" name="subject" value="Form Submission" />
<input type="hidden" name="redirect" value=" thankyou.html" />
<p>First Name:<input type="text" name="FirstName" /></p>
<p>Last Name:<input type="text" name="LastName" /></p>
<p>E-Mail:<input type="text" name="email" /></p>
<p>Comments:<textarea name="comments" cols="40" rows="10">
Type comments here.</textarea></p>
<input type="submit" name="submit" value="submit"/>
</form>

Save and upload your file to your hosting account.

NOTE: Your file and GDFORM.PHP need to be placed in the same directory of your hosting account in order for the form to properly function.

 

PHP

<?php $auth = "shirlene.chadick@gmail.com";


$deny = NULL;
$must = NULL;
$post = NULL;
$http = NULL;
$form = NULL;
$list = NULL;


if (!isset($_POST)) {
$_POST = &$HTTP_POST_VARS;
}
if (!isset($_SERVER)) {
$_SERVER = &$HTTP_SERVER_VARS;
}
if (!function_exists('array_key_exists')) {
function array_key_exists($key, $array) {return in_array($key, array_keys($array)) ? true : false;}
}


if (get_magic_quotes_gpc()) {
foreach ($_POST as $key => $value) {
$_POST["$key"] = stripslashes($value);
}
}


if (strstr(php_uname(), 'Windows')) {
$IS_WINDOWS = TRUE;
}

$deny = "nobody@*, anonymous@*, postmaster@*";

function array_trim(&$value, $key) {
$value = trim($value);
}

function get_domain($string) {
if (eregi('\.?([a-zA-Z0-9\-]+\.?[a-zA-Z0-9\-]+)$', $string, $values)) {
return $values[1];
}

return NULL;
}

function error_msg($error, $required = FALSE) {
global $post;

if (!empty($post['missing_fields_redirect']) && $required) {
header('Location: ' . $post['missing_fields_redirect']);
}
elseif (!empty($post['error_redirect'])) {
header('Location: ' . $post['error_redirect']);
}
else {
echo "<html>\r\n";
echo "\t<head>\r\n";
echo "\t\t<title>Form Error</title>\r\n";
echo "\t\t<style type=\"text/css\">* {font-family: \"Verdana\", \"Arial\", \"Helvetica\", monospace;}</style>\r\n";
echo "\t</head>\r\n";
echo "\t<body>\r\n";
echo "\t\t<p>${error}</p>\r\n\t\t<p><small>« <a href=\"javascript: history.back();\">go back</a></small></p>\r\n";
echo "\t</body>\r\n";
echo "</html>\r\n";
}

exit();
}


function pattern_grep($input, $array) {
foreach ($array as $value) {
$value = addcslashes($value, '^.[]$()|{}\\');
$value = str_replace('*', '.*', $value);
$value = str_replace('?', '.?', $value);
$value = str_replace('+', '.+', $value);

if (eregi('^' . $value . '$', $input)) {
return TRUE;
}
}

return FALSE;
}


if ($_SERVER['REQUEST_METHOD'] == 'POST') {

$post = array(
'recipient' => $_POST['recipient'],

'subject' => $_POST['subject'],

'required' => $_POST['required'],



);

$http = array(
'REMOTE_USER' => $_SERVER['REMOTE_USER'],
'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'],
'HTTP_USER_AGENT' => $_SERVER['HTTP_USER_AGENT']
);

if (isset($must['required'])) {
$post['required'] = $must['required'] . ',' . $_POST['required'];
}
if (isset($must['env_report'])) {
$post['env_report'] = $must['env_report'] . ',' . $_POST['env_report'];
}
if (isset($must['redirect'])) {
$post['redirect'] = $must['redirect'];
}
if (isset($must['error_redirect'])) {
$post['error_redirect'] = $must['error_redirect'];
}
if (isset($must['missing_fields_redirect'])) {
$post['missing_fields_redirect'] = $must['missing_fields_redirect'];
}

if (($auth = explode(',', $auth))) {
array_walk($auth, 'array_trim');
}
if (($deny = explode(',', $deny))) {
array_walk($deny, 'array_trim');
}


if ((!empty($post['required'])) && ($list = explode(',', $post['required']))) {
$list[] = 'recipient';


array_walk($list, 'array_trim');

foreach ($list as $value) {
if (!empty($value) && empty($_POST["$value"])) {
error_msg("You have left a required field blank.", TRUE);
}
}
}




if ((!empty($post['recipient'])) && ($list = explode(',', $post['recipient']))) {
array_walk($list, 'array_trim');

foreach ($list as $value) {

if (!pattern_grep($value, $auth)) {
error_msg("The recipient's email address is unauthorized.");
}
}
}
else {
error_msg("There was an unknown error while checking the recipients email address.");
}


if ((!empty($post['sort'])) && ($list = explode(',', $post['sort']))) {
array_walk($list, 'array_trim');

foreach ($list as $value) {
$form["$value"] = $_POST["$value"];
}
}
else {
$form = $_POST;
}


$subject = empty($post['subject']) ? "Online form" : "Online form: " . $post['subject'];

$message = "Submitted on: " . date('l, F jS, Y @ g:i:s a (O)') . "\r\n\r\n";

if (!empty($post['env_report'])) {
if (($list = explode(',', $post['env_report']))) {
$message .= "Client Variables\r\n";
$message .= "----------------\r\n\r\n";

array_walk($list, 'array_trim');

foreach ($list as $value) {
if (array_key_exists($value, $http)) {
$message .= "${value}:\r\n" . $http["$value"] . "\r\n\r\n";
}
}
}
}

$message .= "Online Form Fields\r\n";
$message .= "------------------\r\n\r\n";

foreach ($form as $key => $value) {
if (!array_key_exists($key, $post)) {
$message .= "${key}:\r\n${value}\r\n\r\n";
}
}


if (mail($post['recipient'], $subject, $message, "From: " . "\r\nReply-To: " . "\r\nX-Mailer: PHP FormMail")) {

if (!empty($post['redirect'])) {
header('Location: ' . $post['redirect']);
}
else {
echo "<html>\r\n";
echo "\t<head>\r\n";
echo "\t\t<title>Thank you</title>\r\n";
echo "\t\t<style type=\"text/css\">* {font-family: \"Verdana\", \"Arial\", \"Helvetica\", monospace;}</style>\r\n";
echo "\t</head>\r\n";
echo "\t<body>\r\n";

echo "\t\t<p>Thank you for completing this form. </p>\r\n\t\t<p>« <a href=\" http://www.chadick.net/crus-aid/index.html\">Click here to return to Crus/Aid.</a></p>\r\n\t\t"; echo "\t<br><br><br>"; echo "\t</body>\r\n"; echo "</html>\r\n"; } } else { error_msg("There was an unknown error while sending email."); } } else { error_msg("Invalid request method used."); } ?>

 

HTML

<!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=iso-8859-1" />
<title>Crus/Aid Industries Inc. - Free Sample</title>

<style type="text/css">

<!--
.style0 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #cc0000; font-size: x-large; font-style: italic; font-weight: bold;
}
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #cc0000;
}
.style2 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #000066; font-size: medium;
}
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #cc0000; font-size: x-small;
}
.style4 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #000066; font-size: large;
}
.style5 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small;
}
.style6 {font-family: Verdana, Arial, Helvetica, sans-serif; color: #000066; font-size: small; font-style: italic;
}
.style7 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small; color: #cc0000;
}
-->

</style>

</head>

<body background="images/ca_bkgd.jpg" LINK="#cc0000" VLINK="#cc0000">

<br>
<br>

<table width="80%" align="center" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><img src="images/crus-aid.png" /></td>
</tr>
</table>

<br>
<br>

<table width="80%" align="center" border="2" bordercolor="#000066" cellspacing="2" cellpadding="10">
<tr>
<td bgcolor="#f5f5f5"><h2 class="style1">Free Sample</h2>

<p>Items marked with * are required</p>

<!-- added open table tag / edited submit -->
<table align="center">
<!-- 1 company name -->
<tr>
<td width="286"><span class="style5">*Company Name</span></td>
<td width="504"><input name="1" type="text" size="50"></td></tr>

<!-- 2 your name -->
<tr>
<td width="286"><span class="style5">*Your Name</span></td>
<td><input name="2" type="text" size="50"></td></tr>

<!-- 3 phone -->
<tr>
<td width="286"><span class="style5">*Your Phone & Extension</span></td>
<td><input name="3" type="text" size="50"></td></tr>

<!-- 4 email -->
<tr>
<td width="286" height="28"><span class="style5">*Your E-mail Address</span></td>
<td><input name="4" type="text" size="50"></td></tr>

<!-- 5 ship to -->
<tr>
<td width="286"><span class="style5">*Ship To Address</span></td>
<td><input name="5" type="text" size="80"></td></tr>

<!-- 6 type plastics -->
<tr>
<td width="286"><span class="style5">*Type plastics to be cleaned</span></td>
<td><input name="6" type="text" size="80"></td></tr>

<!-- 7 type process -->
<tr>
<td width="286"><span class="style5">*Type process / equipment size to be tested</span></td>
<td><input name="7" type="text" size="80"></td></tr>

<!-- 8 results -->
<tr>
<td width="286"><span class="style5">Desired results expected</span></td>
<td><input name="8" type="text" size="80"></td></tr>

<!-- 9 other -->
<tr>
<td width="286"><span class="style5">Other useful information</span></td>
<td valign="top"><input name="9" type="text" size="80"></td></tr>

<!-- required fields -->
<input type="hidden" name="required" value="1,2,3,4,5,6,7">

<!-- mailto -->
<input type="hidden" name="recipient" value=" shirlene.chadick@gmail.com"><tr><td></td><td><input type="submit" value="SUBMIT REQUEST" /></td>
</tr>
</table>

</form></p>

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

<br>
<br>

<table align="center" width="70%" border="0">
<tr>
<td width="12%" align="center"><span class="style7"><a href="index.html ">ABOUT US</a></span></td>
<td width="12%" align="center"><span class="style7"><a href="products.html">PRODUCTS</a></span></td>
<td width="12%" align="center"><span class="style7"><a href="information.html">INFORMATION</a></span></td>
<td width="12%" align="center"><span class="style7"><a href=" safety.html">SAFETY</a></span></td>
<td width="12%" align="center"><span class="style7"><a href="order.html">ORDERING</a></span></td>
<td width="12%" align="center"><span class="style7"><a href="sample.html">FREE SAMPLE</a></span></td>
<td width="12%" align="center"><span class="style7"><a href=" disclosure.html">DISCLOSURE</a></span></td>
<td width="12%" align="center"><span class="style7"><a href="contact.html">CONTACT US</a></span></td>
</tr>
</table>

<br>

<table width="45%" align="center" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="10%" align="center"><img src="images/tx_tilt.gif" /></td>
<td width="90%" align="center"><span class="style3"><a href="mailto: Bob@Crus-Aid.com">Crus/Aid Industries, Inc.</a>    PO Box 267    Keller TX 76180<br>
Voice 817.428.5781    Fax 817.428.7563<br />
Copyright © 2007 – All rights reserved.  Contact <a href=" mailto:webmaster@crus-aid.com">Webmaster</a>.</span></td>
</tr>
</table>

</body>
</html>

EDITED BY WILDTEEN88: Please use the code tags (


) when posting code - espeically large blocks of code. I have reformatted your post for you.

Link to comment
Share on other sites

Uh, sorry, I'm new just in case that wasn't obvious.  Thank you ACE, for adding the tags for my code.

 

The submit button on the form (made from code I bought from Forms4free) didn't work, and Forms4free said I'd left part of it out.  They replaced the missing code, tested it on their server and I received their submitted test form via email as I should.

 

I uploaded their code to Godaddy (my web host) and it now partially works.  If you leave a required field blank, you get the expected warning message.  However, with the form correctly filled out, the submit button now takes you to a page with the message "there was an unknown error while sending email".  What should appear, with a correctly filled form submitted, is a "thank you" page.

 

I've compared my php file to Godaddy's help page verbage, and none of it makes sense to me.  Thank you all in advance.

Link to comment
Share on other sites

Ok, i suggest you email goddady back and ask them if you HAVE to use their mailer. Ask them if you can use your own. It sounds to me like they've set up something to help people send emails, but it may be that the script you've bought is more suited to your needs.

 

If it is the case that godaddy only permit the use of their emailer, then that is why the script you bought does not work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.