Page 1 of 1

PHP Submit Recipient HELP

Posted: Fri May 28, 2010 7:38 pm
by Loren
Help. I am trying to code the following but it will not send to my email box. Can someone help me

Code: Select all

<?php
   if ($_SERVER['REQUEST_METHOD'] != 'POST'){
      $me = $_SERVER['PHP_SELF'];
?>

<h5>Vairalbe Information to be Embossed</h5>

<form id="frm_message" name="frm_message" method="post" action="<?php echo $me;?>">

<fieldset>
<input type="hidden" name="subject" value="Varialbe Information to be Embosssed" />

		<ul>		
			<li>

				<label class="description" for="Company">Company: </label>
				
					<input name="Name" id="company" type="text" size="45" class="element text" value="" />
					
				

			</li>

			<li>
				<label class="description" for="contactPerson">Contact Person: </label>
			
					<input name="contact" id="contact" type="text" size="45" class="element text" value="" />
		


			</li>
            <li>
				<label class="description" for="phoneNumber">Phone Number: </label>
			
					<input name="phone" id="phone" type="text" size="25" class="element text" value="" />
		


			</li>

			<li>
				<label class="description" for="email">Email: <span class="required">*</span></label>
				
					<input name="email" id="email" type="text" class="element text" size="45" value="" />
	<p class="error hidden" id="err_email"></p>
			</li>
 	
			<li>

				<label class="description" for="line1">Line 1: </label>
				
					<input name="$msg" id="line1" type="text" size="25" maxlength="25" class="element text" value="" />
					
				

			</li>

			<li>
				<label class="description" for="line2">Line 2: </label>
			
					<input name="$msg" id="line2" type="text" size="25" class="element text" maxlength="25" value="" />
		


			</li>
            <li>
				<label class="description" for="line3">Line 3: </label>
			
					<input name="$msg" id="Line3" type="text" size="25" class="element text" maxlength="25" value="" />
		


			</li>

			<li>
				<label class="description" for="Line4">Line 4: </label>
				
					<input name="line4" id="line4" type="text" class="element text" size="25" maxlength="25"  value="" />
	
			</li>
            <li>
				<label class="description" for="Line5">Line 5: </label>
				
					<input name="$msg" id="line4" type="text" class="element text" size="25" maxlength="25" value="" />
	
			</li>
          </ul>        
</fieldset>

<fieldset>
  <ul>
    

    
    <li>
 <input name="Submit" type="submit" value="Submit" />
 
  
 
      
    </li>
  </ul>
</fieldset>

</form>
<?php
   } else {
      error_reporting(0);
      $recipient = 'lorenwtaylor@gmail.com';
      $subject = stripslashes($_POST['Subject']);
      $from = stripslashes($_POST['Name']);
      $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
      if (mail($recipient, $subject, $msg))
         echo nl2br("<b>Message Sent:</b>
         To: $recipient
         Subject: Varialbe Information to be Embosssed
         Message:
         $msg");
      else
         echo "Message failed to send";
}
?>

Re: PHP Submit Recipient HELP

Posted: Fri May 28, 2010 10:06 pm
by Brenden
The first problem that I can see is that you're trying to email the post variable "MsgBody", which doesn't appear anywhere in the actual form. Is it giving you any error messages, a blank screen, the form again? Be more specific than "will not send"

Also you have four inputs all names "$msg" surrounding one named "Line4". Wouldn't it be better in this case to use <textarea name='MsgBody'></textarea>

You should use !isset($_POST['Name']) instead of $_SERVER['REQUEST_METHOD'] != 'POST', a lot of people seem to have trouble with request_method

Re: PHP Submit Recipient HELP

Posted: Sat May 29, 2010 2:59 pm
by Loren
Brendon Thanks for the help! Now I am getting a blank screen! I have to have separate lines on the form for line 1 ...5. Do you see the error of my ways...

Thanks in advance

Code: Select all

<?php
   if !isset($_POST['Name']){
      $me = $_SERVER['PHP_SELF'];
?>



<h5>Vairalbe Information to be Embossed</h5>

<form id="frm_message" name="frm_message" method="post" action="<?php echo $me;?>">

<fieldset>
<input type="hidden" name="subject" value="Varialbe Information to be Embosssed" />

		<ul>		
			<li>

				<label class="description" for="Company">Company: </label>
				
					<input name="Name" id="company" type="text" size="45" class="element text" value="" />
					
				

			</li>

			<li>
				<label class="description" for="contactPerson">Contact Person: </label>
			
					<input name="contact" id="contact" type="text" size="45" class="element text" value="" />
		


			</li>
            <li>
				<label class="description" for="phoneNumber">Phone Number: </label>
			
					<input name="phone" id="phone" type="text" size="25" class="element text" value="" />
		


			</li>

			<li>
				<label class="description" for="email">Email: <span class="required">*</span></label>
				
					<input name="email" id="email" type="text" class="element text" size="45" value="" />
	<p class="error hidden" id="err_email"></p>
			</li>
 	
			<li>
          

				<label class="description" for="line1">Line 1: </label>
				
					<input name="MsgBody" id="line1" type="text" size="25" maxlength="25" class="element text" value="" />
					
				

			</li>

			<li>
				<label class="description" for="line2">Line 2: </label>
			
					<input name="MsgBody" id="line2" type="text" size="25" class="element text" maxlength="25" value="" />
		


			</li>
            <li>
				<label class="description" for="line3">Line 3: </label>
			
					<input name="MsgBody" id="Line3" type="text" size="25" class="element text" maxlength="25" value="" />
		


			</li>

			<li>
				<label class="description" for="Line4">Line 4: </label>
				
					<input name="MsgBody" id="line4" type="text" class="element text" size="25" maxlength="25"  value="" />
	
			</li>
            <li>
				<label class="description" for="Line5">Line 5: </label>
				
					<input name="MsgBody" id="line4" type="text" class="element text" size="25" maxlength="25" value="" />
	
			</li>
          </ul>        
</fieldset>

<fieldset>
  <ul>
    

    
    <li>
 <input name="Submit" type="submit" value="Submit" />
 
  
 
      
    </li>
  </ul>
</fieldset>

</form>
<?php
   } else {
      error_reporting(0);
      $recipient = 'lorenwtaylor@gmail.com';
      $subject = stripslashes($_POST['Subject']);
      $from = stripslashes($_POST['Name']);
      $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
      if (mail($recipient, $subject, $msg))
         echo nl2br("<b>Message Sent:</b>
         To: $recipient
         Subject: Varialbe Information to be Embosssed
         Message:
         $msg");
      else
         echo "Message failed to send";
}
?>

Re: PHP Submit Recipient HELP

Posted: Sat May 29, 2010 6:02 pm
by Brenden
Ok you still have five inputs named 'MsgBody'. They need to be called different things, or your form will only receive one of them. You are missing an open round bracket after the first IF, and you are missing curly brackets all over the place during your actual message sending, after the IF and on both sides of the ELSE. I cannot provide an example because for some reason this forum ruins any brackets I put into it.

Re: PHP Submit Recipient HELP

Posted: Sun May 30, 2010 7:59 pm
by Loren
Hi Brendon
Ok I have cleaned up the code and still having problems. It will not send via email the posted information and for some reason the echo will not display.

Thank again


<?php

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>



<h5>Vairalbe Information to be Embossed</h5>

<form id="frm_message" name="frm_message" method="post" action="<?php echo $PHP_SELF;?>">

<fieldset>
<input type="hidden" name="subject" value="Varialbe Information to be Embosssed" />

<ul>
<li>

<label class="description" for="Subject">Subject: </label>

Vairalbe Information to be Embossed </li>
<li>

<label class="description" for="Company">Company: </label>

<input name="Name" id="company" type="text" size="45" class="element text" value="" />



</li>

<li>
<label class="description" for="contactPerson">Contact Person: </label>

<input name="contact" id="contact" type="text" size="45" class="element text" value="" />



</li>
<li>
<label class="description" for="phoneNumber">Phone Number: </label>

<input name="phone" id="phone" type="text" size="25" class="element text" value="" />



</li>

<li>
<label class="description" for="email">Email: <span class="required">*</span></label>

<input name="email" id="email" type="text" class="element text" size="45" value="" />
<p class="error hidden" id="err_email"></p>
</li>

<li>


<label class="description" for="line1">Line 1: </label>

<input name="line1" id="line1" type="text" size="25" maxlength="25" class="element text" value="" />



</li>

<li>
<label class="description" for="line2">Line 2: </label>

<input name="line2" id="line2" type="text" size="25" class="element text" maxlength="25" value="" />



</li>
<li>
<label class="description" for="line3">Line 3: </label>

<input name="line3" id="Line3" type="text" size="25" class="element text" maxlength="25" value="" />



</li>

<li>
<label class="description" for="Line4">Line 4: </label>

<input name="line4" id="line4" type="text" class="element text" size="25" maxlength="25" value="" />

</li>
<li>
<label class="description" for="Line5">Line 5: </label>

<input name="line5" id="line4" type="text" class="element text" size="25" maxlength="25" value="" />

</li>
</ul>
</fieldset>

<fieldset>
<ul>



<li>
<input name="Submit" type="submit" value="Submit" />




</li>
</ul>
</fieldset>

</form>


<?
} else {
error_reporting(0);
$Subject = $_POST["Subject"];
$Name = $_POST["Name"];
$contact = $_POST["contact"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$line1 = $_POST["line1"];
$line2 = $_POST["line2"];
$line3 = $_POST["line3"];
$line4 = $_POST["line4"];
$line5 = $_POST["line5"];
$recipient = 'lorenwtaylor@gmail.com';
if (mail($recipient, $subject, $Name, $contact, $phone, $line1, $line2, $line3, $line4, $line5))
echo nl2br("<b>Message Sent:</b>
To: $recipient
Subject: $subject
");
else
echo "Message failed to send";
}
?>