Page 1 of 1

Php powered form not sending mail.

Posted: Sat Jun 25, 2011 2:34 pm
by microskies
hey all,
I recently made a form for my website, that uses the php mail() function. It worked perfectly well on it's own, in the root directory, until I put it into a file called 'form_body.html' as a custom page on my forums (in a different directory, but I have made sure all links are correct)...
It is supposed to send an email to 'Microskies@hotmail.co.uk' with all the details entered in the form, on the email.
This did all work well and how i wanted to when i first tested it in the root directory, as is shown by this email:

Builder Application From Microskies (******@live.co.uk)

We have received the following information:

IGN: Microskies
E-mail: pagey94@live.co.uk
Rank: Builder
Application Reason: BEHwq
Suggestions:
Picture: hjewrw

(The form has developed a bit since then, so it isn't completely reflective of the php and form below)

I may consider putting the form into an iframe as a last resort... but anyway, so you can see if i have gone wrong, or what needs to be done, here are the files:

application.php:

Code: Select all

<?php 
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

page_header('Application Form');

$template->set_filenames(array(
    'body' => 'form_body.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
<?php
// Start form action
 $to = "microskies@hotmail.co.uk" ; 
 $from = $_REQUEST['email'] ; 
 $ign = $_REQUEST['ign'] ;
 $rank = $_REQUEST['rank'] ; 
 $pic = $_REQUEST['pic'] ;
 $message = $_REQUEST['message'] ;
 $headers = "$rank Application From $ign ($from)"; 
 $subject = "$rank Application From $ign ($from)"; 
 
 $fields = array(); 
 $fields{"ign"} = "IGN"; 
 $fields{"rname"} = "Real Name";
 $fields{"age"} = "Age";
 $fields{"email"} = "E-mail"; 
 $fields{"rank"} = "Rank"; 
 $fields{"message"} = "Application Reason"; 
 $fields{"suggestions"} = "Suggestions"; 
 $fields{"pic"} = "Picture (Link)"; 
 
 
 $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ 	$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
  
 $headers2 = "From: $to"; 
 $subject2 = "Thank you for Applying"; 
 $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at http://wincraft.host56.com";
 
 if($ign == '') {
 print "You have not entered an In-Game-Name, please go back and try again";
 } else {
 if($from == '') {
 print "You have not entered an E-mail, please go back and try again";
 } else {   
 if($rank == '') {
 print "You have not chosen a rank, please go back and try again";
 } else {
 if($message == '') {
 print "You have not entered a reason why you would like to join the server, please go back and try again";
 } else {
 if($pic == '') {
 print "You have not entered a link to a screenshot of your work, please go back and try again";
 } else {
 $success = mail($to, $subject, $body, $headers); 
 $success2 = mail($from, $subject2, $autoreply, $headers2);}
 if($send) {
 header( "Location: http://wincraft.host56.com" );
 } else {
 print "We encountered an error sending your mail, please notify microskies@hotmail.co.uk"; 
 } 
 }
}
}
}
 ?> 
and here is the form_body.html:

Code: Select all

<!-- INCLUDE overall_header.html -->

<h2>Application Form</h2>


	
	
<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="content">
      <p>
	  
 <form id="application" name="application" method="post" action="/application.php">
	
	<div class="FormDesignerField">
		<label for="field1" class="RequiredField">
			Your In Game Name
		</label>
		<input type="text" id="field1" name="ign" style="cursor:text" />
	</div>
	
	<div class="FormDesignerField">
		<label for="field9">
			Your real name &Dagger;
		</label>
		<input type="text" id="field9" name="rname" maxlength="20" size="25" style="cursor:text" />
	</div>


	<div class="FormDesignerField">
		<label for="field10">
			Your age &Dagger;
		</label>

			<input type="text" id="field10" name="age" size="3" maxlength="3" style="cursor:text"/>
	</div>	
	
	<div class="FormDesignerField">
		<label for="field3" class="RequiredField">
			Your e-mail address
		</label>

			<input type="text" id="field3" name="email" size="30" style="cursor:text" />

	</div>
	
	<div class="FormDesignerField">
		<label for="field4" class="RequiredField">
			Rank Applying For
		</label>
		<select id="field4" name="rank">
			<option value="Explorer">
				Explorer
			</option>
			<option value="Builder">
				Builder
			</option>
		</select>
	</div>
	
	<div class="FormDesignerField">
		<label for="field5">
			How long have you been playing Minecraft?
		</label>

			<input type="text" id="field5" name="how_long" maxlength="40" size="25" style="cursor:text" />

	</div>
	
	<div class="FormDesignerField">
		<label for="field6" class="RequiredField">
			Why are you applying for the chosen rank?
		</label>
		<textarea id="field6" name="message" rows="6" cols="30"></textarea>
	</div>
	
	<div class="FormDesignerField">
		<label for="field7">
			Any suggestions for the server?
		</label>
		<textarea id="field7" name="suggestions" rows="4" cols="30"></textarea>
	</div>

	<div class="FormDesignerField">
		<label for="field8" class="RequiredField" >
			A link (or multiple) to a screenshot of a past creation &dagger;
		</label>

			<input type="text" id="field8" name="pic" size="40" style="cursor:text" />

	</div>

	<div class="FormDesignerField ButtonField">
		<input type="submit" id="submit" value="Apply!" name="send" />
	</div>
	
	<div class="FormDesignerField ButtonField">
		<input type="reset" id="field9" value="Reset" name="field9" />
	</div>
	</form>        
		 		 
      </p>
   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->

Re: Php powered form not sending mail.

Posted: Sat Jun 25, 2011 2:35 pm
by microskies
Oh yeah, link to the page is : http://wincraft.host56.com/application.php

Re: Php powered form not sending mail.

Posted: Sun Jun 26, 2011 4:40 am
by microskies
I've figured out whaty i was.... I needed to have two seperate php files