Jump to content

[SOLVED] PHP issue ... simple perhaps?!


Recommended Posts

Hi all,

 

First post here and i'm totally stuck.

 

I'm hosting a website and running an entry competition as we speak.

 

Page 1 = select a file to upload and continue

Page 2 = Enter name, email address, phone number and info on the picture

Page 3 = Thank you and confirmation.

 

Page 2 is where everything comes together, and is also not working.

 

There is a form with 5 fields in it:

 

fname, lname, email, phone and info

 

This is emailed using the following:

 

if ($_POST['xx'] == 'ctx') {

$body = 'The Competition Entry form was submitted on: ' . date('F j, Y, g:i a') . ' by ' . $_POST['email'] . ' at IP: ' . $_SERVER['REMOTE_ADDR'];

if ($_SERVER['HTTP_VIA']) {

$via = explode(' ',$_SERVER['HTTP_VIA']);

$body .= ' (via ' . $via[1] . ')';

} if ($_SERVER['HTTP_X_FORWARDED_FOR']) $body .= ' [Forwarded For: ' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ']';

$body .= "\n\nDetails:\n\n" . $_POST['fname'] . ' ' . $_POST['lname'] . "\n" . $_POST['email'] . "\n" .  $_POST['phone'] . "\n" .  "\n\nPicture Details:\n\n" . $_POST['info'] . "\n\nFile Details:\n\n" . print_r($_SESSION['up_files'],true) . "\n\n";

@mail('xxxx@xxxxx.com','xxxxxx - Competition Entry',$body);

}

 

The above works fine.

 

The problem is with the form method.

 

Currently, it's set to this:

 

<form method="post">

BLAH

<input type="submit" value="Send Entry" style="margin-left: 230px;" />

 

However, on submit it emails but doesnt redirect me to page3. Yes - I know there is no action on here.

 

When I have:

 

<form method="post" action="?page=comp3">

 

it redirects me fine to the page, but then doesn't email me the info!

 

I've tried all sorts and I am sure its something very basic.

 

If anyone can help, i'd be most appreciative!

 

Lee

 

Link to comment
https://forums.phpfreaks.com/topic/84484-solved-php-issue-simple-perhaps/
Share on other sites

With that little code, it's hard to help you. However, you still need to have the form submit to the place where the processing is done - e.g. where the email is sent. It's no good having the form submit straight to the thankyou page, otherwise the email wont ever get sent.

 

You need to submit your form to whichever page sends the email, and add on a header redirect once the email is sent:

 

//once email is sent:
header("location:thankyoupage.php");

 

p.s, try to remember to enclose your code inside

 tags (without the spaces) it's much more readable!

 

Oh, and welcome to the site

Thanks for the reply.

 

Below is the full code from the second page. This page pulls the image name from the array $_SESSION as  well as the fields from the current page. On submit, these are all emailed.

 

However, I want it to email, then redirect to a thank you page.... ?

 

<?
# vim:ft=php:
if (!$_SESSION['up_files']) header('Location: index.php?page=comp');
$_PAGE['color'] = 'orange';

if ($_POST['xx'] == 'ctx') {
	$body = 'The Competition Entry form was submitted on: ' . date('F j, Y, g:i a') . ' by ' . $_POST['email'] . ' at IP: ' . $_SERVER['REMOTE_ADDR'];
	if ($_SERVER['HTTP_VIA']) {
		$via = explode(' ',$_SERVER['HTTP_VIA']);
		$body .= ' (via ' . $via[1] . ')';
	} if ($_SERVER['HTTP_X_FORWARDED_FOR']) $body .= ' [Forwarded For: ' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ']';
	$body .= "\n\nDetails:\n\n" . $_POST['fname'] . ' ' . $_POST['lname'] . "\n" . $_POST['email'] . "\n" .  $_POST['phone'] . "\n" .  "\n\nPicture Details:\n\n" . $_POST['info'] . "\n\nFile Details:\n\n" . print_r($_SESSION['up_files'],true) . "\n\n";
	@mail('xxxxxxx@xxx.com,'xxxxxxxxxxx',$body);
}

?>

<div class="indented">
<strong>Your Details</strong><br /><br />

<form method="post">
<input type="hidden" name="xx" value="ctx" />
<table>
<tr>
<td class="ordertbl">First Name:</td>
<td class="ordertbl"><input type="text" name="fname" value="<?= $_SESSION['fname'] ?>" /></td>
</tr>
<tr>
<td class="ordertbl">Last Name:</td>
<td class="ordertbl"><input type="text" name="lname" value="<?= $_SESSION['lname'] ?>" /></td>
</tr>
<tr>
<td class="ordertbl">E-Mail Address:</td>
<td class="ordertbl"><input type="text" name="email" value="<?= $_SESSION['email'] ?>" /></td>
</tr>
<tr>
<td class="ordertbl">Phone Number:</td>
<td class="ordertbl"><input type="text" name="phone" value="<?= $_SESSION['phone'] ?>" /></td>
</tr>
<tr>
<td class="ordertbl">Information on the picture (location, settings etc) </td>
<td class="ordertbl"><input type="text" name="info" value="<?= $_SESSION['info'] ?>" /></td>
</tr>
<br />
<strong>Review your Entry</strong>
<br />
<br />

<?
$i = 0;
foreach ($_SESSION['up_files'] as $imgrec) {
	echo "<li id=\"imgli$i\"><img alt=\"";
	echo $imgrec['name'] . "\" src=\"upload/";
	echo basename($imgrec['new_path']) . "\" width=\"170\" height=\"120\"/></li>\n\n"; $i++;

}
?>
<tr><td colspan="2"> </td></tr>

<tr><td colspan="2"><span style="margin-left: 150px;"><input type="submit" value="Send Entry" style="margin-left: 230px;" />Note - click only once!</span></td></tr>
<tr></tr>
</table>
</form>
</div>

So it's all working, we just need to add in the redirect? Try:

 

<?php
# vim:ft=php:
if (!$_SESSION['up_files']) header('Location: index.php?page=comp');
$_PAGE['color'] = 'orange';

if ($_POST['xx'] == 'ctx') {
	$body = 'The Competition Entry form was submitted on: ' . date('F j, Y, g:i a') . ' by ' . $_POST['email'] . ' at IP: ' . $_SERVER['REMOTE_ADDR'];
if ($_SERVER['HTTP_VIA']) {
	$via = explode(' ',$_SERVER['HTTP_VIA']);
	$body .= ' (via ' . $via[1] . ')';
}
if ($_SERVER['HTTP_X_FORWARDED_FOR']){ 
	$body .= ' [Forwarded For: ' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ']';
}
$body .= "\n\nDetails:\n\n" . $_POST['fname'] . ' ' . $_POST['lname'] . "\n" . $_POST['email'] . "\n" .  $_POST['phone'] . "\n" .  "\n\nPicture Details:\n\n" . $_POST['info'] . "\n\nFile Details:\n\n" . print_r($_SESSION['up_files'],true) . "\n\n";
if(mail('xxxxxxx@xxx.com','xxxxxxxxxxx',$body)){
	header("location:thankyou.php");
}else{
	echo 'Email could not be sent!';
}
}

?>

<div class="indented">
<strong>Your Details</strong><br /><br />

<form method="post">
<input type="hidden" name="xx" value="ctx" />
<table>
<tr>
<td class="ordertbl">First Name:</td>
<td class="ordertbl"><input type="text" name="fname" value="<?= $_SESSION['fname'] ?>" /></td>
</tr>
<tr>
<td class="ordertbl">Last Name:</td>
<td class="ordertbl"><input type="text" name="lname" value="<?= $_SESSION['lname'] ?>" /></td>
</tr>
<tr>
<td class="ordertbl">E-Mail Address:</td>
<td class="ordertbl"><input type="text" name="email" value="<?= $_SESSION['email'] ?>" /></td>
</tr>
<tr>
<td class="ordertbl">Phone Number:</td>
<td class="ordertbl"><input type="text" name="phone" value="<?= $_SESSION['phone'] ?>" /></td>
</tr>
<tr>
<td class="ordertbl">Information on the picture (location, settings etc) </td>
<td class="ordertbl"><input type="text" name="info" value="<?= $_SESSION['info'] ?>" /></td>
</tr>
<br />
<strong>Review your Entry</strong>
<br />
<br />

<?php
$i = 0;
foreach ($_SESSION['up_files'] as $imgrec) {
	echo "<li id=\"imgli$i\"><img alt=\"";
	echo $imgrec['name'] . "\" src=\"upload/";
	echo basename($imgrec['new_path']) . "\" width=\"170\" height=\"120\"/></li>\n\n"; $i++;

}
?>
<tr><td colspan="2"> </td></tr>

<tr><td colspan="2"><span style="margin-left: 150px;"><input type="submit" value="Send Entry" style="margin-left: 230px;" />Note - click only once!</span></td></tr>
<tr></tr>
</table>
</form>
</div>

 

One more request, try and use full php opening tags(<?php) when you post your code here, syntax highlighting makes things much easier to read.

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.