Jump to content

attaching generated pdf to form and send in phpmailer


mythri

Recommended Posts

Hi All,

I am able to generate pdf and send that generated pdf as attachment to entered email-id. But i want something like, when i click on email it should generate pdf and open a form with user entry fields like To, Message, Subject.... etc... And that generated pdf should show as attachment

Now when click on email it will open an user entry form then when i click on send , it will generate pdf and send that pdf.

Here is my code

My html form

<form method="post" action="send_mail.php" enctype="multipart/form-data">
<div class="formSep">
<label class="req">To Email: </label>
<input type="text" name="email" />      <select name="email"><option value="">Select one</option><?php $s1 = mysql_query("select * from lead_contact where company_id=".$company."");
while($r1 = mysql_fetch_array($s1)) { $name = $r1['firstname'].' '.$r1['lastname'];
$cid = $r1['con_id'];
$cemail = $r1['email']; ?>
<option value="<?php echo $cemail;?>"><?php echo $name;?></option>
<?php
}
?>
</select>
</div>
<input type="hidden" name="order_id" value="<?php echo $order_id; ?>" />
<input type="hidden" name="company" value="<?php echo $company; ?>" />

<div class="formSep">
<label class="req">Subject</label>
<input type="text" name="subject" /></div>

<div class="formSep">
<label class="req"> Message</label>


<div class="w-box" id="n_wysiwg">
<div class="w-box-header">
<h4>WYSIWG Editor</h4>
</div>
<div class="w-box-content cnt_no_pad">
<textarea name="message" id="wysiwg_editor" cols="30" rows="10"></textarea>
</div>
</div>
</div>


<div class="formSep">

<input type="submit" name="submit" value="Submit" class="btn btn-info" /></div>

</form>

send_email.php

<?php
if($_POST['submit'] == "Submit")
{
    
    $id = $_POST['order_id'];
    $company = $_POST['company'];
    include("../admin_auth.php");
    
    
include("../connect.php");
require('invoice.php');

$pdf = new PDF_Invoice( 'P', 'mm', 'A4' );
$pdf->AddPage();


//MY PDF CODE GOES HERE



$pdf->Output("D:/wamp/www/folder/uploads/".$id.".pdf","F");

$path = "D:/wamp/www/folder/uploads/".$id.".pdf";
require("class.phpmailer.php");
require("class.smtp.php");



$to = $_POST['email'];
$from = $_SESSION['email'];
$message = $_POST['message'];

$subject = $_POST['subject'];

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "hostname";

$mail->SMTPAuth = true;
$mail->Username = 'user';
$mail->Password = 'password';
$mail->Port = 587;
$mail->From=$_SESSION['email'];
$mail->FromName=$_SESSION['name'];
$mail->Sender=$email;


$mail->AddAddress($to);



$mail->AddBCC("test@test.com");
$mail->AddAttachment($path, '', $encoding = 'base64', $type = 'application/pdf');
$mail->Subject = $subject;

$mail->CharSet="windows-1251";
$mail->CharSet="utf-8";

$mail->IsHTML(true);


$mail->Body = $message;


if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
echo "Email Sent!";
}
}
?>

I am not getting how to get the form with pdf attached, so that user can write in the body , add cc and sent email

 

Link to comment
Share on other sites

From your somewhat readable post, it sounds like you are getting what you want but then you say you aren't.

 

What exactly does "click on email" mean?  Are you clicking on an email message somewhere?

 

Sounds like you want to present the user with a form to collect the data you want and then have the action direct you to a script that grabs those inputs and also generates the pdf and then does the email send for you.  So - what's the problem?

Link to comment
Share on other sites

What do you mean by "but pdf is not getting attached in the form"?  "attached IN the form"?  Whatever is that?

 

From your (again - sketchy) description it sounds like the pdf is something you create, not something that you get "from a form".  Please make yourself a bit clearer.

Link to comment
Share on other sites

Sorry for my communication.

 

I will be displaying data like this

 

post-168283-0-52195900-1498234278_thumb.png

 

When i click on email symbol, it should generate a pdf and display a user entry form with generated pdf as attachment. The form should be like

 

post-168283-0-15075100-1498234456_thumb.png

 

 

 

Link to comment
Share on other sites

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.