0
votes

Problems (only after hitting submit)

  1. The email is not displaying the html form or its results, it's only sending the number "1" in multiple emails

  2. The form results are displaying on the next page (need to send to other page)

I have a form on my website and I wanted to send the results from that form to my email. However, I want the results to be in the same format that the form was in. So I'm not familiar with php and I researched how to send an email and I got that working. After looking at it I realized that it would be much easier to read the form information if it was in a form. I copied and pasted the html over to the php and put it all inside of the print tag. I went further and inserted readonly tags inside of the inputs on the form before I inserted placeholder tags to display the form results. The issue I'm having is that when I hit submit the form is displayed on the next page and the email I receive only has the number 1 inside of the email body...and I get several emails at once with the same message.

Extra:

1.The php code is below, I only put placeholders on the first three inputs because I just needed a couple inputs to test if the script worked.

2.The original html form(not below) has "name" tags so the results I enter are displaying when I hit submit.

3.If you read the code you only need to pay attention to the first three inputs, all the rest are there for a visual purpose. Later on I wanted to see how much of the form I could put inside of the email and how much styling as well.

<?php

$to = '[email protected]';

$subject = "New Mortgage Form ($name)";

$message = Print'
<form>
    <div id="AppInfo">
        <br>
        <span style="text-decoration: underline; font-size: 1.2em;">Applicant Information</span> <br><br>

        Name: <input type="text" title="name" placeholder="' .$_POST['name']  . '" readonly> <br> <br>
        Address: <input type="text" title="address" placeholder="' .$_POST['address']  . '" readonly> <br> <br>
        Rent/Own: <input type="text" title="rentown" placeholder="' .$_POST['rentown']  . '" readonly> <br><br>

        How Long: <input type="text" title="length" readonly> <br><br>
        Prior Address: <input type="text" title="prior" readonly> <br><br>
        DOB: <input type="text" title="dob" readonly> <br><br>
        Marital Status: <input type="text" title="marital" readonly> <br><br>
        SSN: <input type="number" title="estValue" readonly> <br><br>
        Home:<input type="tel" title="home" readonly> <br><br>
        Cell: <input type="tel" title="cell" readonly> <br><br>
        Employer: <input type="text" title="emp" readonly> <br><br>
        Position: <input type="text" title="empPosition" readonly> <br><br>
        Address: <input type="text" title="empAddress" readonly> <br><br>
        Monthly Salary: <input type="number" title="empSalary" readonly> <br><br>
        Date Hired: <input type="date" title="empHired" readonly> <br><br>
        Commission, Overtime, Child Support, etc: <br>
        &nbsp&nbsp&nbsp <input type="text" title="c.o.c.e" readonly> <br><br>
        Wk <input type="number" title="work" readonly> <br><br>
        Fax <input type="number" title="fax" readonly> <br><br>
        Self Employed: &nbsp Yes<input type="checkbox" title="seYes" readonly> &nbsp&nbsp No<input type="checkbox" title="seNo" readonly> <br><br>
        How Long: <input type="text" title="seLength" readonly> <br><br>
    </div>

    <br><br><br>

    <div id="MoDebt">
        <span style="text-decoration: underline; font-size: 1.2em;">Monthly Debts</span>
        &nbsp&nbsp&nbsp&nbsp&nbsp
        <br><br>
        Rent/Mortgage Payment: <input type="text" title="Rent or Mortgage Payment Amount Monthly"> <br> <br>
        Car Payment: <input type="text" title="Car Payment Amount Monthly"> <br> <br>
        Make/Model/Year: <input type="text" title="Make of car/Model of car/Year of car"> <br><br>
        Student Loans: <input type="text" title="Student Loans Amount Monthly"> <br><br>
        Credit Cards: <input type="text" title="Credit Cards Amount Monthly"> <br><br>
        Child Support: <input type="text" title="Child Support Amount Monthly"> <br><br>
        Other: <input type="text" title="Other Debt Amounts Monthly"> <br><br>
    </div>';



// send email
mail($to, $subject, $message);

?>
2
I just found an alternative option: Attachments! However, I would still want to figure out this current question...Bijan Kelley
It might be because you are printing the message. Which wil return true. So remove the print there.Hans Dubois
Follow this: php.net/manual/en/function.mail.php and update the script, Your script sending 1 because the headers are not present in the script, so add appropriate headers and send email.Nikhil
you are not assigning the form to the $message variable: you are assigning the print result of that form to the variable. Just remove Print at the beginning of the $message variable and it will be fixedLelio Faieta

2 Answers

1
votes

You need set Content-type: text/html to header email. http://php.net/manual/en/function.mail.php

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";
mail($to,$subject,$message,$headers)
1
votes

Problem 1: You are actually setting the $message variable to the result of the Print ''; call which always returns a 1, which will be sent as your message.

Second problem is due to the same print call too.

You should try this I mean :

    <?php

$to = '[email protected]';

$subject = "New Mortgage Form ($name)";

$message = '
<form>
    <div id="AppInfo">
        <br>
        <span style="text-decoration: underline; font-size: 1.2em;">Applicant Information</span> <br><br>

        Name: <input type="text" title="name" placeholder="' .$_POST['name']  . '" readonly> <br> <br>
        Address: <input type="text" title="address" placeholder="' .$_POST['address']  . '" readonly> <br> <br>
        Rent/Own: <input type="text" title="rentown" placeholder="' .$_POST['rentown']  . '" readonly> <br><br>

        How Long: <input type="text" title="length" readonly> <br><br>
        Prior Address: <input type="text" title="prior" readonly> <br><br>
        DOB: <input type="text" title="dob" readonly> <br><br>
        Marital Status: <input type="text" title="marital" readonly> <br><br>
        SSN: <input type="number" title="estValue" readonly> <br><br>
        Home:<input type="tel" title="home" readonly> <br><br>
        Cell: <input type="tel" title="cell" readonly> <br><br>
        Employer: <input type="text" title="emp" readonly> <br><br>
        Position: <input type="text" title="empPosition" readonly> <br><br>
        Address: <input type="text" title="empAddress" readonly> <br><br>
        Monthly Salary: <input type="number" title="empSalary" readonly> <br><br>
        Date Hired: <input type="date" title="empHired" readonly> <br><br>
        Commission, Overtime, Child Support, etc: <br>
        &nbsp&nbsp&nbsp <input type="text" title="c.o.c.e" readonly> <br><br>
        Wk <input type="number" title="work" readonly> <br><br>
        Fax <input type="number" title="fax" readonly> <br><br>
        Self Employed: &nbsp Yes<input type="checkbox" title="seYes" readonly> &nbsp&nbsp No<input type="checkbox" title="seNo" readonly> <br><br>
        How Long: <input type="text" title="seLength" readonly> <br><br>
    </div>

    <br><br><br>

    <div id="MoDebt">
        <span style="text-decoration: underline; font-size: 1.2em;">Monthly Debts</span>
        &nbsp&nbsp&nbsp&nbsp&nbsp
        <br><br>
        Rent/Mortgage Payment: <input type="text" title="Rent or Mortgage Payment Amount Monthly"> <br> <br>
        Car Payment: <input type="text" title="Car Payment Amount Monthly"> <br> <br>
        Make/Model/Year: <input type="text" title="Make of car/Model of car/Year of car"> <br><br>
        Student Loans: <input type="text" title="Student Loans Amount Monthly"> <br><br>
        Credit Cards: <input type="text" title="Credit Cards Amount Monthly"> <br><br>
        Child Support: <input type="text" title="Child Support Amount Monthly"> <br><br>
        Other: <input type="text" title="Other Debt Amounts Monthly"> <br><br>
    </div>';



// send email
mail($to, $subject, $message);

?>