Trying to understand this script

I have a form
http://www.ronisvonhelms.com/
this is in send.php

<?php

if ($_GET["email"] == "attempt"){
$to='lurtnowski@gmail.com';
$messageSubject='RonisVonHelms Contact Form';
$email='';
$body='';
$name = $_POST['name'];
$phone = $_POST['phone'];


if ($_POST){
$email=stripslashes($_POST['email']);
$body=stripslashes($_POST['body']);

$msgbody = "<table><tr><th>Name</th><td>".$name."</td></tr>";
$msgbody .= "<tr><th>Phone</th><td>".$phone."</td></tr>";
$msgbody .= "<tr><th>Email</th><td>".$email."</td></tr>";
$msgbody .= "<tr><th>Body</th><td>".$body."</td></tr></table>";

	
	if ($email && $body){
   if (mail($to,$messageSubject,$msgbody,'From: '.$email."\r\n")){
   
?>

<?php header( 'Location: ?v=success' ) ; ?>
<?php
    echo '<p>'.htmlspecialchars($body).'</p>';
    }
 }
 }
}
?>

I understand everything, but what does this mean…
<?php header( 'Location: ?v=success' ) ; ?>

Thanks…

That will essentially redirect the browser to the SAME URL but with the ?v=success on the end.

So if you were on this URL: http://site.com/page.php

It would redirect here.

http://site.com/page.php?v=success

the result is

But Where is the green msg coming from?

also im not sure the mail() is even being sent, is there a way I can make sure?

The fact that you even get the message indicates PHP successfully engaged it’s mail function, and deposited the email for delivery. That does not, however, mean that the mail was successfully delivered, as that relies on far more than just PHP. (Your host mail server, the receiving mail server, etc)

In theory you should be seeing the below error with that script.

Warning: Cannot modify header information - headers already sent by (output started at x:y) in x on line y

If you don’t receive that error chances are mail() is returning false and the header function is never being called.

The space after the end of the first php code block begins sending output. Once output has began sending the headers can’t be modified. So you need to remove that space or better yet just place that entire script in a single code block.

Somewhere in the code for that page will be code looking for $GET[‘v’] being equal to ‘success’ and that will display the message.

Maybe there is output buffering in operation elsewhere in the page.

Did a little digging and noticed a few quirks…
After I fill out the form at
http://www.ronisvonhelms.com/index.php
Heres a screenshot of the PHP page

Heres a screenshot of the result

for some reason (can you explain it to me) The form is handled by send.php file 1 folder above the includes folder
Heres the screenshot of the contact form…

Then, heres a SS of the send.php file (1 folder above the includes folder)

I’m not sure what you’re asking here for the first question. What exactly is it that you want explaining? If it’s the green ack message above the form, you need to show the whole php code that draws that page.

The From-address used for the email is handled in that last screen-shot, but the code to add it to the mail headers ends in “/r/n” rather than the more usual “\r\n” that you use on the next few lines, so that might confuse it. There’s no attachment to show the resulting email.

Please, though - paste code as text in code tags, not as screen shots. There isn’t enough in there to show what might be happening on the first one, I think you really need to show all the code for the page, not just the part around the form display. And on my low-bandwidth connection it takes ages to load the full-size images, without which I can’t read any of the text.

For example, the code might be checking for “success” and altering the CSS to display a message that usually has “display: none” attributes set, and that might not be anywhere near the code to display the form. Without seeing it all, it’s impossible to say. In the code for that page, what do you find if you search for the word “success”?

Oh, i was confused cause I had an include with an include in it and I thought it was looking for the include inside the include directory and instead it was looking for the include from the page calling the first include.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.