Hi All,
I am able to generate pdf and send that generated pdf as attachment to entered email-id. But i want, 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
[CODE]<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!";
}
}
?>
Can you please guide me how to do it?