Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在提交后发送pdf格式的表单数据和邮件_Php_Forms_Fpdf - Fatal编程技术网

Php 如何在提交后发送pdf格式的表单数据和邮件

Php 如何在提交后发送pdf格式的表单数据和邮件,php,forms,fpdf,Php,Forms,Fpdf,我已经制作了一个简单的表单,它接受值,但是现在我想制作一个pdf格式的表单数据,当我点击提交时,意味着在提交表单后,当使用时,点击提交,那么所有表单值都将是pdf格式。(我想通过邮件发送pdf文件,但首先我想了解如何制作pdf文件,然后我会稍后再做。) 我已经为表单编写了代码,然后我使用fpdf的帮助,并试图理解其类的用法 <?php require('fpdf.php'); /*$pdf = new FPDF(); $pdf->AddPage();

我已经制作了一个简单的表单,它接受值,但是现在我想制作一个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';?>
这是我的大脑不工作的部分,因为我不知道这个代码。请告诉我如何从表格中获取数据并将其放入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。在其中,您只需要传递HTML内容


对于电子邮件发送和附件

在获得大量搜索和负面标记后..我确实解决了我的问题

只需编辑mypdf.php

mypdf.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");
}

?>

Thanx nikunj但我从那里得到的只是一堆复杂的代码..虽然fpdf很简单,但我不明白我怎么能得到pdf格式的表单数据,即使我包含了数据函数,所以请检查并告诉我..真的是Thanx:)但是请尝试fpdf并解决plzm尝试,现在我把我的表单文件而不是$file放在上面的代码中,那又怎么样我得到的是,首先我必须将所有提交的数据放在一个文件中,然后我必须在这里提供该文件,以便数据将以pdf格式保存。我说得对吗?@rico…。你做了任何更改吗?或ans?
<?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");
}

?>