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
Try this..
$path = "D:/wamp/www/folder/uploads/".$id.".pdf";
$mail->addCC('cc@example.com'); //Cc stands for carbon copy
$mail->addBCC('bcc@example.com'); //Bcc stands for blind carbon copy
$mail->AddAttachment($path, '', $encoding = 'base64', $type = 'application/pdf');
NOTE: FOR REFERENCE OF PHP MAILER :
Check This: https://github.com/PHPMailer/PHPMailer
Cc stands for carbon copy which means that whose address appears after the Cc: header would receive a copy of the message. Also, the Cc header would also appear inside the header of the received message.
Bcc stands for blind carbon copy which is similar to that of Cc except that the Email address of the recipients specified in this field do not appear in the received message header and the recipients in the To or Cc fields will not know that a copy sent to these address.
It really helps if you get your basic PHP syntax right. This is just meaningless:
$mail->AddAttachment($path, '', $encoding = 'base64', $type = 'application/pdf');
All you need is this:
$mail->AddAttachment($path);
It will take care of the rest for you.