PHP email format

  • theshangsta
  • Newbie
  • Newbie
  • theshangsta
  • Posts: 6

Post 3+ Months Ago

Hello there
Sorry if this is considered double posting at this forum- it is not intended to be, I'm just spinning off another recent thread of mine.

I'm having a bit of trouble collecting the data i need using PHP.

I'm using the same PHP script i used for my contact us page, but modified it.

My problem is that when i recieve the email, it will only send me one field value at a time...for example I only recieve the user's name in my email when I should be collecting their name, address, credit card, etc......This was never a problem for my contact page because the only input field is the body of the message anyway.

also, when the data is returned to me I need a better way of organizing it; right now if it sends me back someones name for example, it will simply say in the first and only line of my email message: John Smith.
I would like it to say Name: John Smith, in other words Iwould like to receive the data in the closest form possible to the way i distributed it. if I ask for an email on my form i want it to come back as Email: email @ email . com

PHP Code: [ Select ]
<?php
 
$name = trim($_POST['name']);
$location = trim($_POST['location']);
$city = trim($_POST['city']);
$zip = trim($_POST['zip']);
$home = trim($_POST['home']);
$cell = trim($_POST['cell']);
$office = trim($_POST['office']);
$primaryfax = trim($_POST['primaryfax']);
$local = trim($_POST['local']);
$localfax = trim($_POST['localfax']);
$from = trim($_POST['from']);
$problem = trim($_POST['problem']);
$previousproblem = trim($_POST['previousproblem']);
$company = trim($_POST['company']);
$service = trim($_POST['service']);
 
function checkEmail($from)
{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $from))
   {
      return FALSE;
   }
 
   list($Username, $Domain) = split("@",$from);
   
   if(getmxrr($Domain, $MXHost))
   {
      return TRUE;
   }
   else
   {
      if(fsockopen($Domain, 25, $errno, $errstr, 30))
      {
         return TRUE;
      }
      else
      {
         return FALSE;
      }
   }
}
 
if( isset( $_POST['submit'] ) || !empty( $_POST['submit'] ) )
{
    $errors = '';
   
    if(checkEmail($from) == FALSE)
    {
   
        if( empty($from) )
        {
            $errors .= "<br/><strong>Please enter a valid Email address</strong><br/><br/>";
        } else {
            $errors .= "<strong>Your E-mail address entered is not valid, please go back and try again.<br/><br/></strong>";
        }
    }
   
    if ( empty($name) ) { $errors .= "<strong>Please enter your full name.<br/><br/></strong>"; }
   
    if ( empty($location) ) { $errors .= "<strong>Please enter a valid service call location.<br/><br/></strong>"; }
 
    echo $errors;
       
    if ( empty($errors) )
    {
        $sendTo = "myemail @ my email . com";
        $subject = SCAF;
        $headers = "From: " . $from;
        $message = $name;$location;
        mail($sendTo, $subject, $message, $headers);
        header("location: http://www .my site. com/thanks.html");        
    }
}
 
?>
  1. <?php
  2.  
  3. $name = trim($_POST['name']);
  4. $location = trim($_POST['location']);
  5. $city = trim($_POST['city']);
  6. $zip = trim($_POST['zip']);
  7. $home = trim($_POST['home']);
  8. $cell = trim($_POST['cell']);
  9. $office = trim($_POST['office']);
  10. $primaryfax = trim($_POST['primaryfax']);
  11. $local = trim($_POST['local']);
  12. $localfax = trim($_POST['localfax']);
  13. $from = trim($_POST['from']);
  14. $problem = trim($_POST['problem']);
  15. $previousproblem = trim($_POST['previousproblem']);
  16. $company = trim($_POST['company']);
  17. $service = trim($_POST['service']);
  18.  
  19. function checkEmail($from)
  20. {
  21.    if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $from))
  22.    {
  23.       return FALSE;
  24.    }
  25.  
  26.    list($Username, $Domain) = split("@",$from);
  27.    
  28.    if(getmxrr($Domain, $MXHost))
  29.    {
  30.       return TRUE;
  31.    }
  32.    else
  33.    {
  34.       if(fsockopen($Domain, 25, $errno, $errstr, 30))
  35.       {
  36.          return TRUE;
  37.       }
  38.       else
  39.       {
  40.          return FALSE;
  41.       }
  42.    }
  43. }
  44.  
  45. if( isset( $_POST['submit'] ) || !empty( $_POST['submit'] ) )
  46. {
  47.     $errors = '';
  48.    
  49.     if(checkEmail($from) == FALSE)
  50.     {
  51.    
  52.         if( empty($from) )
  53.         {
  54.             $errors .= "<br/><strong>Please enter a valid Email address</strong><br/><br/>";
  55.         } else {
  56.             $errors .= "<strong>Your E-mail address entered is not valid, please go back and try again.<br/><br/></strong>";
  57.         }
  58.     }
  59.    
  60.     if ( empty($name) ) { $errors .= "<strong>Please enter your full name.<br/><br/></strong>"; }
  61.    
  62.     if ( empty($location) ) { $errors .= "<strong>Please enter a valid service call location.<br/><br/></strong>"; }
  63.  
  64.     echo $errors;
  65.        
  66.     if ( empty($errors) )
  67.     {
  68.         $sendTo = "myemail @ my email . com";
  69.         $subject = SCAF;
  70.         $headers = "From: " . $from;
  71.         $message = $name;$location;
  72.         mail($sendTo, $subject, $message, $headers);
  73.         header("location: http://www .my site. com/thanks.html");        
  74.     }
  75. }
  76.  
  77. ?>



here is the code, please help asap as i'm in a crunch for time, all help is greatly appreciated, this is an excellent help site....I hope one day to be the one giving advice rather than getting LOL :lol:
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • msj1013
  • Novice
  • Novice
  • msj1013
  • Posts: 24

Post 3+ Months Ago

on line 71:
there is a semicolon between $name and $location
  • ozzyosb100
  • Graduate
  • Graduate
  • User avatar
  • Posts: 191
  • Loc: FL

Post 3+ Months Ago

Yes, You will need to fix that semicolon on line 71 as msj1013 stated. As for organizing the data, I think what you are trying to do will need a $message variable formatted as a long concatenated sting of all the fields in your form. So you may want to replace that line 71 with something like this...

PHP Code: [ Select ]
<?php
$message = "Name: ".$name. "\n\r".
           "Location: ".$location. "\n\r".
           "City: ".$city. "\n\r".
           "Zip: ".$zip. "\n\r".
           "Home: ".$home. "\n\r".
           "Cell: ".$cell. "\n\r";
?>
  1. <?php
  2. $message = "Name: ".$name. "\n\r".
  3.            "Location: ".$location. "\n\r".
  4.            "City: ".$city. "\n\r".
  5.            "Zip: ".$zip. "\n\r".
  6.            "Home: ".$home. "\n\r".
  7.            "Cell: ".$cell. "\n\r";
  8. ?>

... and so on.

each continuing new line will end with a period and the last line needs to end in a semicolon.

depending on the server this is running on, you may need \n\r or just \n. If you want to display the message in the page as HTML use <br \>

Hope this helps.

(edit: fixed punctuation in the code)
Moderator Remark: Edit post removed - no problem ;)
  • theshangsta
  • Newbie
  • Newbie
  • theshangsta
  • Posts: 6

Post 3+ Months Ago

wow ozzy thank you, that saved me a lot of time.

Next question I have is more in regards to HTML and forms i think, but it is related to the PHP that runs the form so I was wondering if anyone could help me out with it.....


(edit- accidentally hit submit lol)

Code: [ Select ]
<table cellspacing=3>
<tr><td>Type of Card:<td colspan="3">
<Input type='Radio'Name='Cardtype'value='Mastercard'>MC
<Input type='Radio'Name='Cardtype'value='Visa'>VISA
<Input type='Radio'Name='Cardtype'value='AMEX'>AMEX</td></tr>

<table cellspacing=3>
<tr><td>Account #:<td colspan="3">
<input size=20 maxlength=20 type=text name=cardnumber
<td>Exp Date:<td colspan="3">
<input size=6 maxlength=6 type=text name=exp
<td>CVV2#:<td colspan="3">
<input size=6 maxlength=6 type=text name=cvv2
<td></td></tr>


<table cellspacing=3>
<tr><td>Name on Card:<td colspan="3">
<input size=50 maxlength=50 type=text name=cardname
</td></tr>


<table cellspacing=3>
<tr><td>Billing Address for above card:<td colspan="3">
<input size=50 maxlength=50 type=text name=address
</td></tr>

<tr><td colspan="3"><Input type = 'checkbox' Name ='agree' value= 'I have read, understand and agree to the terms & conditions of this agreement.'>I have read, understand and agree to the <a href="maintterms.html" target="popsome""> Terms and Conditions</a> of this agreement.</td></tr><br>

<b><u>Comments:</u></b><TEXTAREA NAME="comments" COLS=40 ROWS=6></TEXTAREA>



<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type=submit value=" Submit " name=submit style="font-size: 10pt; font-family: Tahoma"></td></tr>
</table>
</div>
</form>
                        
                                                

                        </div>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td bgcolor="#B1DDF2" style="border-top: 1px solid #015885">
  1. <table cellspacing=3>
  2. <tr><td>Type of Card:<td colspan="3">
  3. <Input type='Radio'Name='Cardtype'value='Mastercard'>MC
  4. <Input type='Radio'Name='Cardtype'value='Visa'>VISA
  5. <Input type='Radio'Name='Cardtype'value='AMEX'>AMEX</td></tr>
  6. <table cellspacing=3>
  7. <tr><td>Account #:<td colspan="3">
  8. <input size=20 maxlength=20 type=text name=cardnumber
  9. <td>Exp Date:<td colspan="3">
  10. <input size=6 maxlength=6 type=text name=exp
  11. <td>CVV2#:<td colspan="3">
  12. <input size=6 maxlength=6 type=text name=cvv2
  13. <td></td></tr>
  14. <table cellspacing=3>
  15. <tr><td>Name on Card:<td colspan="3">
  16. <input size=50 maxlength=50 type=text name=cardname
  17. </td></tr>
  18. <table cellspacing=3>
  19. <tr><td>Billing Address for above card:<td colspan="3">
  20. <input size=50 maxlength=50 type=text name=address
  21. </td></tr>
  22. <tr><td colspan="3"><Input type = 'checkbox' Name ='agree' value= 'I have read, understand and agree to the terms & conditions of this agreement.'>I have read, understand and agree to the <a href="maintterms.html" target="popsome""> Terms and Conditions</a> of this agreement.</td></tr><br>
  23. <b><u>Comments:</u></b><TEXTAREA NAME="comments" COLS=40 ROWS=6></TEXTAREA>
  24. <td>&nbsp;</td>
  25. <td>&nbsp;</td>
  26. <td><input type=submit value=" Submit " name=submit style="font-size: 10pt; font-family: Tahoma"></td></tr>
  27. </table>
  28. </div>
  29. </form>
  30.                         
  31.                                                 
  32.                         </div>
  33.                     </td>
  34.                 </tr>
  35.             </table>
  36.         </td>
  37.     </tr>
  38.     <tr>
  39.         <td bgcolor="#B1DDF2" style="border-top: 1px solid #015885">



I seem to be having trouble with the "textarea" field.....It wont publish where I want it to....using that code it just sits in between credit card name and billing address, I want it to be the last input before the submit button. I have tried using <td> and <tr> and while they place my TEXTAREA in the right place, for some reason it makes the space between "Billing Address for above card" and it's user input far too wide, to the point where it makes my whole page out of proportion and too far to the right.

Any help would be greatly appreciated, and thanks again for the help so far.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 147 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.