簡體   English   中英

提交后如何以pdf和郵件形式發送表單數據

[英]How to send form data in pdf and mail after submit

我做了一個簡單的表單,它接受值,但現在我想制作一個提交表單數據的pdf,當我在提交表單后點擊提交意味着使用時將點擊提交然后所有表單值都將是pdf表單。 (我想通過郵件發送該 pdf,但首先我想了解如何制作 pdf,然后我再做。)

我已經為表單編寫了代碼,然后我使用 fpdf 的幫助並嘗試了解其類的使用。

    <?php
    require('fpdf.php');

    /*$pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->SetTextColor(50,60,100);
    $pdf->AddPage('P');
    $pdf->SetDisplayMode(real,'default');
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output();
    */

$labelname = "Membership Form" ;
 include_once 'header.php';?>

我只是將這些類放在評論中,否則我的 members-form.php 將不會顯示,而空白的 pdf 頁面將顯示。

據我所知,我必須使用 addpage、cell 和 setfont 等函數來設置 pdf 的樣式,並且為了放置數據,我應該使用這個:

function ChapterBody($file)
{
    // Read text file
    $txt = file_get_contents($file);
    // Font
    $this->SetFont('Times','',12);
    // Output text in a 6 cm width column
    $this->MultiCell(60,5,$txt);
    $this->Ln();
    // Mention
    $this->SetFont('','I');
    $this->Cell(0,5,'(end of excerpt)');
    // Go back to first column
    $this->SetCol(0);
}

這是我無法思考的部分,因為我不知道這段代碼。 請告訴我如何從表單中獲取數據並將其放入 pdf,以便在提交后以 pdf 格式顯示。

這是我表格的一小部分

<table border="0" width="100%;">
<form action="mail_handler.php" method="post">
<tr>
<td>Title</td>
<td>First Name</td>
<td>Middle</td>
<td>Surname</td>
</tr>
<tr>
<td><input type="text" name="title" /> </td>
<td><input type="text" name="fname" /></td>
<td><input type="text" name="middle" /></td>
<td><input type="text" name="surname" /></td>
</tr>

<tr>
<td>Mailing Address</td>
</tr>
<tr>
<td><input type="text" name="email" /></td>
</tr>

<tr>
<td colspan="2">Name of Company / Institution & Address</td>
</tr>
<tr>
<td><input type="text" name="noc" width="30%"/></td>
<td><input type="text" name="noc1" width="30%"/></td>
</tr>

<tr>
<td>Office Tel.</td>
<td>Home Tel.</td>
<td>Mobile No.</td>
<td>E-mail</td>
</tr>
<tr>
<td><input type="text" name="office_no" /> </td>
<td><input type="text" name="Home_no" /></td>
<td><input type="text" name="mobile_no" /></td>
<td><input type="text" name="email" /></td>
</tr>
<tr><td a align="center" colspan="4"><input type="submit" value="submit" name="submit" /></td></tr>
</form>
</table>

我也閱讀了這個問題發送電子郵件填寫的 PDF 表單,但它沒有解決我的問題。

在得到了很多搜索和負面標記之后..我確實解決了我的問題..

只需編輯 mypdf.php

我的pdf.php

<?php
include('pdf.php');

if(isset($_POST['submit']) && $_POST['submit']!='' && $_POST['fname']!='')
{
//for mail(i din use it as m wrking offline but hope it will work
/*$to = "xyz@gmail.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['fname'];
    $last_name = $_POST['surname'];
    $mbile = $_POST['mobile_no'];
    $email = $_POST['email'];
    $subject = "Form submission";
    //$subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " " . $mbile . " " . $email . "\n\n" . $_POST['message'];
    //$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    //mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    // You cannot use header and echo together. It's one or the other.
*/


       $msg = "title: " .$_POST['title'] . "\n"
            ."fname: " .$_POST['fname'] . "\n"
            ."middle: " .$_POST['mail_add'] . "\n"
            ."surname: " .$_POST['mobile_no'] . "\n"
            ."email: " .$_POST['email'] . "\n"
            ."mail_add: " .$_POST['education'];
        $staffEmail = "staffemail";

    // get your $N value for hear





    $h1_heading = "User Detail";
        $pdf_filename = tempnam(sys_get_temp_dir(), "pdf");
        $pname = explode("\\", $pdf_filename);
        $a=$pname[3];
        $pname1 = explode(".", $a);
        $cname=$pname1[0];//final name for file
        $pdf=new FPDF();
        $pdf->AddPage();
        $pdf->SetFont("Arial", "B", 16);
        $pdf->Cell(40, 10, "User Detail");
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "First Name:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['fname']);
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "Address:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['mail_add']);
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "Mobile No:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['mobile_no']);
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "E-mail:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['email']);
        $pdf->Ln();
        $pdf->SetFont("Arial", "", 12);
        $pdf->Cell(40, 10, "Education:");
        $pdf->SetFont("Arial", "B", 12);
        $pdf->Cell(40, 10, $_POST['education']);
        $a=$_POST['mobile_no'];
        $pdf->output("pdf/". "$a" .$cname.".pdf" , 'f');
        $pdf->Ln(45);
        header("Location:index.php");
}
else
{
header("Location:membership-form.php");
}

?>

以供參考:

您可以使用MPDF lib生成 PDF。 在其中你只需要傳遞你的 HTML 內容。

用於電子郵件發送和附件PHP Mailer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM