Page 1 of 1

Email Form

Posted: Thu Nov 23, 2006 6:57 am
by verbena
feyd | 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]


I am not a coder, I have some code that allows a user to send an email via a Form. I have used the code on a couple of sites with no trouble

It goes from a contact form, click submit , this will take it to send.php then it will either take it to error.htm or success.htm

I have just tried to use it in another site and when I ckick submit it takes me to send.php whith a "page not available" message and the send.php page will open on my computer in dreamweaver.

this is the code for the contact form

[syntax="html"]<form name="form1" method="post" action="send.php">
        <table width="600" border="0" cellspacing="10" cellpadding="0">
          <tr>
            <td class="Normal"><div align="right"></div></td>
            <td><div align="left">
              <p class="Head">Contact Us </p>
            </div></td>
          </tr>
          <tr>
            <td class="Normal"><div align="right"><span class="red">*</span>Name</div></td>
            <td><div align="left">
              <input name="Name" type="text" id="Name">
            </div></td>
          </tr>
          <tr>
            <td class="Normal"><div align="right"><span class="red">*</span>Email</div></td>
            <td><div align="left">
              <input name="Email" type="text" id="Email">
              
            </div></td>
          </tr>
          <tr>
            <td valign="top" class="Normal"><div align="right">Comments</div></td>
            <td><div align="left">
              <textarea name="Comment" cols="50" rows="10" id="Comment"></textarea>
            </div></td>
          </tr>
          <tr>
            <td class="Normal"><div align="right">
              <input type="submit" name="Submit" value="Submit">
            </div></td>
            <td><div align="left">
              <input name="Reset" type="reset" id="Reset" value="Reset">
</div></td>
          </tr>
        </table>
      </form>



Then the send.php code[/syntax]

Code: Select all

<?PHP

error_reporting(7);


if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
 $ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
 $ClientIP = $_SERVER['REMOTE_ADDR'];
}

# RegisterGlobals OFF

$FTGName = $_POST['Name'];

$FTGEmail = $_POST['Email'];
$FTGComment = $_POST['Comment'];
$FTGSubmit = $_POST['Submit'];
$FTGReset = $_POST['Reset'];


if (get_magic_quotes_gpc) {
 $FTGName = stripslashes($FTGName);
 
 $FTGEmail = stripslashes($FTGEmail);
 $FTGComment = stripslashes($FTGComment);
 $FTGSubmit = stripslashes($FTGSubmit);
 $FTGReset = stripslashes($FTGReset);
}
# Redirect user to the error page

if ($validationFailed == true) {

 header("Location: error.htm");
 exit;

}

# Email to Form Owner

$emailTo = '"" <myemail@yahoo.com.au>';

$emailSubject = "From website";
$emailSubject = preg_replace('/[\x00-\x1F]/', '', $emailSubject);

$emailFrom = "$FTGEmail";
$emailFrom = preg_replace('/[\x00-\x1F]/', '', $emailFrom);

$emailHeader = "From: $emailFrom\n"
 . "Reply-To: $emailFrom\n"
 . "MIME-Version: 1.0\n"
 . "Content-Type: multipart/alternative; boundary="FTG_BOUNDRY"\n"
 . "X-Sender: $emailFrom\n"
 . "X-Mailer: PHP\n"
 . "X-Priority: 3\n"
 . "Return-Path: $emailFrom\n"
 . "\n";

$emailBody = "--FTG_BOUNDRY\n"
 . "Content-Type: text/plain; charset="ISO-8859-1"\n" 
 . "Content-Transfer-Encoding: 8bit\n"
 . "\n"
 . "Name: $FTGName\n"
 
 . "Email: $FTGEmail\n"
 . "Comment: $FTGComment\n"
 . "Submit: $FTGSubmit\n"
 . "Reset: $FTGReset\n"
 . "\n"
 . ""
 . "\n"
 . "--FTG_BOUNDRY\n"
 . "Content-Type: text/html; charset="ISO-8859-1"\n"
 . "Content-Transfer-Encoding: base64\n"
 . "\n"
 . chunk_split(base64_encode("<HTML>\n"
 . "<head>\n"
 . "<title></title>\n"
 . "</head>\n"
 . "<body>\n"
 . "<table width="500" border="0" cellspacing="0" cellpadding="3">\n"
 . "  <tr>\n"
 . "    <td width="150"><div align="right"><b><font face="Tahoma" size="2">Name:</font></b></div></td>\n"
 . "    <td width="336"><font face="Tahoma" size="2">$FTGName</font></td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 
 . "    <td width="150"><div align="right"><b><font face="Tahoma" size="2">Email:</font></b></div></td>\n"
 . "    <td><font face="Tahoma" size="2">$FTGEmail</font></td>\n"
 . "  </tr>\n"
 . "  <tr>\n"
 . "    <td width="150"><div align="right"><b><font face="Tahoma" size="2">Comment:</font></b></div></td>\n"
 . "    <td><font face="Tahoma" size="2">$FTGComment</font></td>\n"
 . "  </tr>\n"
 . "</table></body></html>\n"
 . "\n"
 . ""))
 . "\n"
 . "--FTG_BOUNDRY--";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

# Redirect user to success page

header("Location: success.htm");
exit;

# End of PHP script
?>


If any one can help it would be much appreciated

Thank you


feyd | 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]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]

Posted: Thu Nov 23, 2006 10:02 am
by evilchris2003
You know that PHP has to parsed by the server
and to use PHP you need the script to reside on a server

Posted: Thu Nov 23, 2006 2:32 pm
by verbena
Hi
No I didn't know that, as I said Im not really a coder. I am just copy and past from another project. Could you explain what you mean please...

Posted: Thu Nov 23, 2006 2:50 pm
by evilchris2003
PHP will only run on a server such as apache Both PHP and apache are freely available to download from the web
PHP here http://www.php.net/ and Apache http://www.apache.org/dyn/closer.cgi
A server is used to host a website to use PHP pages even on your own machine you will need to install web server software it can be a little complicated to set up but there are plenty of tutorials like these here --->>> http://www.ricocheting.com/server/

if you dont want to tdo this you will have to sign up with a provider for some webspace

Posted: Thu Nov 23, 2006 4:42 pm
by verbena
I have tried the same code on a different server. When I clicked the submit button it again sent me to "send.php and a message saying page not exist it should have sent it to success.htm.
However the email was sent through ok.

So this code seems to work fine on one website, I copy and paste it to another server and it doesn't work. I put it on another server and it kind of works????

Posted: Thu Nov 23, 2006 4:46 pm
by evilchris2003
means that it cant find sucess.htm on the server

the sucess file is only a confirmation page and doesnt perform any other function

Posted: Thu Nov 23, 2006 4:46 pm
by feyd
Header level redirection requires using full URLs to the destination. This is apart of the HTTP standard.

Posted: Thu Nov 23, 2006 5:10 pm
by verbena
So does that mean it depends on what level your site is on the server, that is why this code works on some servers and not others?

Posted: Thu Nov 23, 2006 5:13 pm
by jayshields
I don't understand why HTML coders get neck-deep in PHP just to send simple emails from forms.

Code: Select all

<form action="mailto:your.email@domain.com" method="post">
  <input type="text" name="message" />
  <input type="submit" />
</form>

Posted: Thu Nov 23, 2006 5:27 pm
by Chris Corbyn
jayshields wrote:I don't understand why HTML coders get neck-deep in PHP just to send simple emails from forms.

Code: Select all

<form action="mailto:your.email@domain.com" method="post">
  <input type="text" name="message" />
  <input type="submit" />
</form>
Ouch... don't swear on this forum please ;) mailto isn't great. It only works if: a) The client has an email client installed b) The browser is linked with that e-mail client

Add to that the fact that you usually need to click send once the email client opens.

It's obviously an option, but I'd certainy favour PHP.

Posted: Thu Nov 23, 2006 5:38 pm
by jayshields
Yeah, I'm aware of that, and I could've guessed you'd favor PHP: afterall you have developed your own emailing library in PHP!

I think I'd rather give those misconviniences (is that a word?) to the user than learn a new programming language.