Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP form wrong coding

Status
Not open for further replies.

pouna12

MIS
Nov 11, 2010
4
US
When i hit the submit button on my website it says there is something wrong with my php code on line 3? I'm not a php person and have no idea what it means. Please check out my code below and let me know what I'm doing wrong. Any help would be greatly appreciated!THANKS SO MUCH!


<div>&lt;?php <br />
<br />
&nbsp;&nbsp; $your_name = $_GET['your_name']; <br />
&nbsp;&nbsp;&nbsp; $your_email = $_GET['email']; <br />
&nbsp;&nbsp;&nbsp; $your_message = $_GET['message']; <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; $recipient_email - &quot;pouna12@yahoo.com&quot;;<br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; $headers .= 'Content-type: text/html; charset=iso-8859-1'; <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; $content = &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Contact letter&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;br&gt;&quot;; <br />
&nbsp;&nbsp;&nbsp; $content .= &quot;Company: &lt;b&gt;&quot; . $your_company . &quot;&lt;/b&gt;&lt;br&gt;&quot;; <br />
&nbsp;&nbsp;&nbsp; $content .= &quot;Name: &lt;b&gt;&quot; . $your_name . &quot;&lt;/b&gt;&lt;br&gt;&quot;; <br />
&nbsp;&nbsp;&nbsp; $content .= &quot;Phone: &lt;b&gt;&quot; . $your_phone . &quot;&lt;/b&gt;&lt;br&gt;&quot;; <br />
&nbsp;&nbsp;&nbsp; $content .= &quot;E-mail: &lt;b&gt;&quot; . $your_email . &quot;&lt;/b&gt;&lt;br&gt;&lt;hr&gt;&lt;br&gt;&quot;; <br />
&nbsp;&nbsp;&nbsp; $content .= $your_message; <br />
&nbsp;&nbsp;&nbsp; $content .= &quot;&lt;br&gt;&lt;/body&gt;&lt;/html&gt;&quot;; <br />
<br />
&nbsp;&nbsp;&nbsp; mail($recipient,$subject,$content,$headers); <br />
?&gt; <br />
&lt;html&gt; <br />
&nbsp;&nbsp;&nbsp; &lt;body bgcolor=&quot;#282E2C&quot;&gt; <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div align=&quot;center&quot; style=&quot;margin-top:60px;color:#FFFFFF;font-size:11px;font-family:Tahoma;font-weight:bold&quot;&gt; <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Your message was sent. Thank you. <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/div&gt; <br />
&nbsp;&nbsp;&nbsp; &lt;/body&gt; <br />
&lt;/html&gt; <br />
&lt;script&gt;resizeTo(300, 300)&lt;/script&gt;</div>
<br />
<?php

while ($request = current($_REQUEST)) {
if (key($_REQUEST)!='pouna12@yahoo.com') {
$pre_array=split ("&777&", $request);

$post_vars[key($_REQUEST)][0]=preg_replace ("/<[^>]*>/", "", $pre_array[0]);
$post_vars[key($_REQUEST)][1]=preg_replace ("/<[^>]*>/", "", $pre_array[1]);
}
next($_REQUEST);
}



reset($post_vars);


$subject="From ".$post_vars['your_name'][0] ;
$headers= "From: ".$post_vars['your_email'][0] ."\n";
$headers.='Content-type: text/html; charset=iso-8859-1';
$message='';
while ($mess = current($post_vars)) {
if ((key($post_vars)!="i") && (key($post_vars)!="your_email") && (key($post_vars)!="your_name")) {

$message.="<strong>".$mess[1]."</strong>&nbsp;&nbsp;&nbsp;".$mess[0]."<br>";
}
next($post_vars);
}

mail($_REQUEST['pouna12@yahoo.com'], $subject, "
<html>
<head>
<title>Contact letter</title>
</head>
<body>
<br>
".$message."
</body>
</html>" , $headers);
echo ("Your message was successfully sent!");

?>
<script>
resizeTo(300, 300);
</script>
 
I cannot tell what is line 3 as this text looks like it has been mangled in translation. Why all the spaces and breaks?

Code:
&nbsp;&nbsp;&nbsp; $recipient_email - &quot;pouna12@yahoo.com&quot;;<br />

There is something very wrong about that line.

Code:
$recipient_email = "pouna12@yahoo.com";
 
Normally I would ask you to copy and paste the exact error, and tell us what line it is referring to.


However, your code looks like it was sent through an html entity replacing function which means that the first part of your code is not getting run at all.

Then there's the issue with all the other things like variables not being set, or function calls that are not properly terminated.

Its jut a big mess.

There's just so much wrong here it just not practical to try to go in and fix.

Tell us what this is supposed to be doing, and we could whip up a functional version.



There are just too many things wrong with this to even attempt to go in a fix, and fresh take would be a better approach.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Im new with php. I basically have a full flash website and the contact form is through flash. it seems when i hit the submit button it a new window pops up and it says this:
<?php

$your_name = $_GET['your_name'];
$your_email = $_GET['email'];
$your_message = $_GET['message'];

$recipient_email - "pouna12@yahoo.com";


$headers .= 'Content-type: text/html; charset=iso-8859-1';

$content = "<html><head><title>Contact letter</title></head><body><br>";
$content .= "Company: <b>" . $your_company . "</b><br>";
$content .= "Name: <b>" . $your_name . "</b><br>";
$content .= "Phone: <b>" . $your_phone . "</b><br>";
$content .= "E-mail: <b>" . $your_email . "</b><br><hr><br>";
$content .= $your_message;
$content .= "<br></body></html>";

mail($recipient,$subject,$content,$headers);
?>
<html>
<body bgcolor="#282E2C">
<div align="center" style="margin-top:60px;color:#FFFFFF;font-size:11px;font-family:Tahoma;font-weight:bold">
Your message was sent. Thank you.
</div>
</body>
</html>
<script>resizeTo(300, 300)</script>


Warning: reset() [function.reset]: Passed variable is not an array or object in D:\Hosting\5579521\html\contact.php on line 46

Warning: current() [function.current]: Passed variable is not an array or object in D:\Hosting\5579521\html\contact.php on line 53

Warning: mail() [function.mail]: SMTP server response: 503 RCPT first (#5.5.1) in D:\Hosting\5579521\html\contact.php on line 70
Your message was successfully sent!

do i just need to redo my php form all together? im really lost.
 
Warning: reset() [function.reset]: Passed variable is not an array or object in D:\Hosting\5579521\html\contact.php on line 46

This is referring to the reset() function call, it expects an array, but your $postvars variable isn't apparently an array.

Same thing with the current() function.

The email error probably refers to the fact that nowhere in your script are you setting the $subject variable.

This piece code:
Code:
<?php

   $your_name = $_GET['your_name'];
    $your_email = $_GET['email'];
    $your_message = $_GET['message'];
    
    $recipient_email [red]=[/red] "pouna12@yahoo.com";
    
    [red]$subject="Email From Website";[/red]
    
    $headers .= 'Content-type: text/html; charset=iso-8859-1';
    
    $content = "<html><head><title>Contact letter</title></head><body><br>";
    $content .= "Company: <b>" . $your_company . "</b><br>";
    $content .= "Name: <b>" . $your_name . "</b><br>";
    $content .= "Phone: <b>" . $your_phone . "</b><br>";
    $content .= "E-mail: <b>" . $your_email . "</b><br><hr><br>";
    $content .= $your_message;
    $content .= "<br></body></html>";

    mail($recipient,$subject,$content,$headers);
?>
<html>
    <body bgcolor="#282E2C">
        <div align="center" style="margin-top:60px;color:#FFFFFF;font-size:11px;font-family:Tahoma;font-weight:bold">
            Your message was sent. Thank you.
        </div>
    </body>
</html>


With the = fixed as shown, this should work correctly, without the other functions that are causing errors.

The email should be sent assuming of course the SMTP server is properly configured in the sever this is running on.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
hi i tried what you did above and it said this:

Parse error: syntax error, unexpected ':' in D:\Hosting\5579521\html\contact.php on line 3
 
The code above has no : outside quotes, so unless there's code you added to that, that error can not be being shown.

Of course there is the question of the undefined variables which would be producing errors, just not that error. I did not correct that because I though it would be fairly obvious that $your_phone, and $your_company variables are not defined anywhere.

Perhaps less obvious is the fact $headers is not initialized so it will generate a notice.

Code:
[gray]
    $your_name = $_GET['your_name'];
    $your_email = $_GET['email'];
    $your_message = $_GET['message'];
    [red]$headers="";
    [green]/* Assuming that there are form inputs for company, and phone and following the naming pattern you have, you could initialize the corresponding variables as:  */[/green]
    $your_company=$_GET['your_company'];
    $your_phone=$_GET['your_phone'];[/red]
    $recipient_email = "pouna12@yahoo.com";
    
    $subject="Email From Website";
    
    $headers .= 'Content-type: text/html; charset=iso-8859-1';
    
    $content = "<html><head><title>Contact letter</title></head><body><br>";
    $content .= "Company: <b>" . $your_company . "</b><br>";
    $content .= "Name: <b>" . $your_name . "</b><br>";
    $content .= "Phone: <b>" . $your_phone . "</b><br>";
    $content .= "E-mail: <b>" . $your_email . "</b><br><hr><br>";
    $content .= $your_message;
    $content .= "<br></body></html>";
 mail($recipient,$subject,$content,$headers);
?>
<html>
    <body bgcolor="#282E2C">
        <div align="center" style="margin-top:60px;color:#FFFFFF;font-size:11px;font-family:Tahoma;font-weight:bold">
            Your message was sent. Thank you.
        </div>
    </body>
</html> 
[/gray]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
I tried it again and corrected it as you said and it works! thank you so much for your help.:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top