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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.