PHP(表单)电子邮件无法正确发送html设计

时间:2015-12-07 11:31:56

标签: php html forms email

问题(仅在点击提交后)

  1. 电子邮件未显示html表单或其结果,仅在多封电子邮件中发送数字“1”

  2. 表单结果显示在下一页(需要发送到其他页面)

  3. 我的网站上有一个表单,我想将该表单的结果发送到我的电子邮箱。但是,我希望结果与表单的格式相同。所以我不熟悉php,我研究了如何发送电子邮件,我得到了它的工作。看了之后我意识到,如果表单信息是在表单中,那么阅读表单信息要容易得多。我将html复制并粘贴到php并将其全部放在print标签内。在插入占位符标签以显示表单结果之前,我进一步在表单上的输入内插入了readonly标签。我遇到的问题是,当我点击提交时,表单会显示在下一页上,而我收到的电子邮件只有电子邮件正文中的数字1 ...我会立即收到几封电子邮件,并发送相同的邮件。

    附加:

    1. php代码如下,我只在前三个输入上放置占位符,因为我只需要几个输入来测试脚本是否有效。

    2.原始html表单(不在下面)有“name”标签,因此当我点击提交时,我输入的结果会显示。

    3.如果你阅读了代码,你只需要注意前三个输入,其余的都是为了视觉目的。后来我想知道我可以在电子邮件中添加多少表单以及多少样式。

    <?php
    
    $to = 'anyemail@email.com';
    
    $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 个答案:

答案 0 :(得分:1)

您需要将Content-type:text / html设置为标题电子邮件。 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 <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
mail($to,$subject,$message,$headers)

答案 1 :(得分:1)

问题1: 您实际上是将$ message变量设置为Print''的结果;始终返回1的呼叫,将作为您的消息发送。

第二个问题也是由于同样的打印电话。

你应该尝试这个我的意思:

    <?php

$to = 'anyemail@email.com';

$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);

?>