PDA

View Full Version : Help on PHP Form Submit



simonf
01-26-2005, 12:28 PM
Hi

I've writen a script that should work with my form, however it does'nt, any suggestions please:


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>VAGMOSMailer</title>
<body>


<?php
switch ($op) {

case send:

$config = "-finfo@nexgen.co.za";

$subject="Information Request from VAGMOS Web Site";

$txtto="info@vag.co.za"

$msg="Please respond in a timely manner.Thanks in advance";


mail("$txtto","$subject","$msg","$config");
header("Location: http://www.vagmos.co.za/thanks.htm");
?>

<?
break;

On the form itself I have this line:


<form name="frmMail" Action="formmail.php?op=send" method="post">

Odin
01-26-2005, 09:53 PM
Are you getting a parse error? If so, the line:
$txtto="info@vag.co.za"
is missing the semi-colon at the end and the switch statement is unterminated.

In case those are just from cutting the code down for the post and you're not getting a parse error:
Are you getting the emails at info@vag.co.za? If you're checking the script by seeing if the redirect works, then that won't work. Headers need to be sent before any content is outputted so put the PHP code before <html>. If you have other cases that don't need the redirect, and so need the html code, you can leave them where the current PHP code is.

If you aren't getting the emails, then it could be that your web host has register_globals off.
ie: $op is undefined, so nothing will happen in your switch statement. Variables from the query string are stored in the $_GET array (in PHP v4.1 or later), so you would want to replace the switch with:
switch ($_GET['op']) {
case "send":

mwinter
01-26-2005, 10:50 PM
I don't have much to add...


<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">You shouldn't use proprietary character sets. You'd probably be better off using iso-8859-1 (aka Latin 1). Moreover, you should be sending the character set (and content type in general) via HTTP Response headers, not meta elements. Unless your server's "broken" (like mine - I can't change the default character set as that's an administrator operation :(), do this part properly.


switch ($op) {Unless your host's PHP version doesn't support super globals, like $_GET, you should avoid using the EGPCS variables even if they are available.

Mike