Jump to content

php email sending only part of form


stealthmode666

Recommended Posts

I have a form which I use php to extract the data from and send as an html file to my email.

It has a lot of fields (approx 100), but it only sends about 16 of the fields.

It's as if the php runs but before it has finished going through the script it sends the data as an html file. Is this possible?

This is the entire script so far but I see no errors in it?

<?php
$to = ( isset ($_REQUEST['sendto']) ? $_REQUEST['sendto'] : "default 'to' email goes here" ); 
$from = ( isset ($_REQUEST['Email']) ? $_REQUEST['Email'] : "default 'from' email goes here" ) ; 
$name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here" ) ; 
$headers = "From: $from"; 
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$subject = "Members Data From ......"; 
$body = "Robert. .... .com:<br /><br />"; 
$body .= "<table align=left>";
$body .= "<tr>";
$body .= "<td width=\"200px\">Member Name</td><td width=\"200px\"> {$_POST['Member_Name']} </td><td width=\"200px\"></td><td width=\"200px\"></td>";
$body .= "</tr><tr>";
$body .= "<td>Members Contact Number</td><td> {$_POST['telephone']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Members Email Address</td><td> {$_POST['Email']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Loan Amount</td><td> {$_POST['Loan_Amount']} </td>";
$body .= "</tr> <tr>";
$body .= "<td> </td>";

//applicant details
$body .= "</tr><tr>";
$body .= "<th>Main Applicant</th><td> </td><th>Joint Applicant</th>";
$body .= "</tr><tr>";
$body .= "<td>Title</td><td> {$_POST['title']} </td><td>Title</td><td> {$_POST['title1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Surname</td><td> {$_POST['surname']} </td><td>Surname</td><td> {$_POST['surname1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Forname(s)</td><td> {$_POST['forename']} </td><td>Forename(s)</td><td> {$_POST['forname1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Residential Address</td><td> {$_POST['residential']} </td><td>Residential Address</td><td> {$_POST['residential1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Town</td><td> {$_POST['town']} </td><td>Town</td><td> {$_POST['town1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>County</td><td> {$_POST['county']} </td><td>County</td><td> {$_POST['county1']} </td>";
$body .= "</tr><tr>";
[color=red]$body .= "<td>Post Code</td><td> {$_POST['postcode']} </td><td>Post Code</td><td> {$_POST['post1']} </td>";[/color]
$body .= "</tr><tr>";
$body .= "<td>Lived At Address (Years)</td><td> {$_POST['years']} </td><td>Lived At Address (Years)</td><td> {$_POST['years1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Lived At Address (Months)</td><td> {$_POST['months']} </td><td>Lived At Address (Months)</td><td> {$_POST['months1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Home Tel No.</td><td> {$_POST['hometelephone']} </td><td>Home Tel No.</td><td> {$_POST['hometelephone1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Mobile Tel No.</td><td> {$_POST['mobile']} </td><td>Mobile Tel No.</td><td> {$_POST['mobile1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>D.O.B</td><td> {$_POST['dateofbirth']} </td><td>D.O.B</td><td> {$_POST['dateofbirth1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Nationality</td><td> {$_POST['nationality']} </td><td>Nationality</td><td> {$_POST['nationality1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Sex</td><td> {$_POST['sex']} </td><td>Sex</td><td> {$_POST['sex1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Marital Status</td><td> {$_POST['marital']} </td><td>Marital Status</td><td> {$_POST['marital1']} </td>";
$body .= "</tr></table>";
$headers2 = "From: [email protected]"; 
$subject2 = "Thank-you for filling in the Form "; 
$autoreply = "Somebody from.. will get back to you as soon as possible, Thank-you";

if($from == '') {print "You have not entered an Email Address, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a First Name, please go back and try again";} 
else { 
$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
if($send){header( "Location: http://www.....co.uk/r..../thankyou.html" );} 
else 
{print "We encountered an error sending your mail, .....co.uk"; } 
}
}
?>

 

All I am trying to do is send the form fields as a formatted table in html instead of plain text. Please help if you can

 

Link to comment
https://forums.phpfreaks.com/topic/137834-php-email-sending-only-part-of-form/
Share on other sites

I was hoping for some help on this, no-where else to turn, can anybody shed any light on why my script stops halfway and sends the email with missing fields.

I changed it back from the &body .= to an array() to process the form fields, and same problem. It only sends a certain amount of the form fields back to the email address, yet a few days ago it was working fine!!

What happens when you echo the $body var?

 

Since that is what contains the body of the email, I would start there and make sure that the whole body echo's.

 

 

I moved this to my server, and made it send to my email.... the email ends with the marital status. That is what it is coded for. In all 32 fields will be sent as long as the $_POST data is completed correctly.

 

So what fields are not sending??

 

Nate

 

Thanks for taking a look.

I use my server live to do all this as I never got apache and php working on me this end.

Could it be something to do with my host server?

I couldn't see anything wrong with the way I coded it.

Also very new to php and still learning, how would I code it to echo the &body lines?

 

I don't understand what you mean redarrow?

I'm guessing somehow to write the code that uses only one $body element yet includes all the formatting for the table and table data from my form.

If so, I need to see how this is written. simply because I have no idea.

 

For a form to be processed with php and send the data, I understood it to be 1 or 1,000+ fields, regardless of the quantity as it runs the script till it's done?

I have looked at you sig but it never helped me because i'm dumb at the moment to php and really struggling. Don't you just love noobies?

Let me give you a clue.

 

Thanks i love newbees ,I am one as well dont no every think only what i ve come across,

 

well i can see your using post in the email $body far as i no email dont like the $_POST function.

 

so you add it to a variable get me.

 

example

 

$readarrow=$_POST['redarrow'];

 

now in the body ill use the variable $redarrow like i say i dont no much but ive noticed $_POST and $_GET['']

some times mucks the email up.

 

your have to use variables in all the code my recommendations then it should all work.

 

 

Okay, I think I understand, but this means I have to make over 200 variables for the $POST function. (not a problem)

The form is massive, but this is not important

Do I code these, leave them above the $body .= and use each variable in the $body?

As in can you show me a line of what it should look like or have I to work it out for myself?

try this live see how it works ok.

<?php

//ini_set("SMTP", " ip address");
//ini_set("smtp_port", "25");

if ($_POST['submit']){

if($_GET['page']=="contact_send"){

	$FullName = Trim(stripslashes($_POST['full_name'])); 
        $Email = Trim(stripslashes($_POST['email'])); 
        $Message = Trim(stripslashes($_POST['message'])); 

$to = 'your email address';

$subject = 'Testing mail!';


$mes = "Hello; \n\n You have recieved an email from ";
$mes .= "you website's contact form. The message is below for your convenience. \n\n ****************************** \nFull Name: ";
$mes .= $full_name;
$mes .= "\n";
$mes .= "Email: ";
$mes .= $Email;
$mes .= "\n";
$mes .= "Message: ";
$mes .= $Message;
$mes .= "\n ****************************** \n\n This Is An Automatically Generated Message, Do Not Repond!";

$message = $mes;

$headers = 
        'X-Mailer: PHP/' . phpversion() . "\r\n" .
        "MIME-Version: 1.0\r\n" .
        "Content-Type: text/html; charset=utf-8\r\n" .
        "Content-Transfer-Encoding: 8bit\r\n\r\n";

// Send
if(mail($to, $subject, $message, $headers)){

echo "<center><em>Thank You " . $_POST['full_name'] . " , Your Message Has Been Sent!</em></center>";

}else{
  
echo "<center><em>There Was An Error Sending The Message, Please Try Again!</em></center>";
}
  }
   }
?>

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>?page=contact_send">

<table width="100%" border="0">
    <tr>
      <td>Full Name:</td>
      <td><span id="sprytextfield1">
        <label>
        <input type="text" name="full_name" id="full_name">
        </label>
      <span class="textfieldRequiredMsg">You Must Enter Your Full Name!</span></span></td>
    </tr>
    <tr>
      <td>E-Mail Address:</td>
      <td><span id="sprytextfield2">
        <label>
        <input type="text" name="email" id="email">
        </label>
      <span class="textfieldRequiredMsg">You Must Enter Your E-Mail Address!</span></span></td>
    </tr>
    <tr>
      <td>Message:</td>
      <td><span id="sprytextarea1">
        <label>
        <textarea name="message" id="message" cols="45" rows="5"></textarea>
        </label>
      <span class="textareaRequiredMsg">You Must Enter A Message To Send!</span></span></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td colspan="2"><label>
        <div align="center">
          <input type="submit" name="submit" id="button" value="Send Message">
        </div>
      </label></td>
    </tr>
  </table>
</form>

Hi redarrow, I'm back again after some sleep. How do I write the code to use a variable in place of the $_POST in my script?

each form field has a different name as you see by my start of coding in my script.

My form submits to the php script which runs and also displays a new .php page to say thank-you to the user + sends an email to say their details have been received. (Well it should, but thats a differnt matter)

I don't understand your script or how to use it to make my email send the data in a formatted table

Redarrow, I'm back again. Yes your script works but it is not for me. I have .js validation on the server checking the form before submit is allowed.

How would I write my code to make the $_POST into a variable?

Sorry to be stuck but i'm struggling here.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.