jeffw77
Posts: 2
|
| Posted: 10/21/2007, 2:38 PM |
|
SuperPDF works great--PHPMailer works great!
Now I wish to sent the $ResultFileName as the attachment via PHPMailer. I can send attachments easily with PHPMailer and I can easily pluck values from components for the mail instruction but I am trying to combine the "Convert to PDF" code followed by the PHPMailer code to handle all this with one click. Here is the attempt sample code for PHPMailer that works except for grabbing the result file
require("class.phpmailer.php");
$mail = new PHPMailer();
$var1 = $employees->email_address->GetValue();
$var2 = $employees->user_id->GetValue();
$var3 = $employees->city->GetValue();
$var4 = $employees->state->GetValue();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.mail.wowway.com;smtp.mail.wowway.com"; // specify main and backup server
$mail->SMTPAuth = false; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = ""; // SMTP password
$mail->From = "myaddress@wowway.com";
$mail->FromName = "FromName";
$mail->AddAddress("$var1", "ToName");
$mail->AddReplyTo("myaddress@wowway.com", "FromName");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->AddAttachment("$ResultFileName"); // add attachments
//$mail->AddAttachment("introduction.pdf", "new.pdf"); // optional name
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "my first php mail";
$mail->Body = "Now I am sending data!<br>$var2<br>$var3<br>$var4<br>I am done transmitting";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
//echo "Message has been sent";
And here is the standard generated code for the pdf creation
//Convert Page to PDF @19-D440F433
if (CCGetFromGet("_convert")) {
global $main_block;
$Command = '"' . "C:\\Program Files\\SuperPDF\\bin\\pdftool.exe" . '"';
$Options = "{InputFile} -f {ResultFile} -root {Root}";
$TempFolder = isset($_ENV["TEMP"]) ? $_ENV["TEMP"] : getenv("TEMP");
if (CCSubStr($TempFolder, -1) != DIRECTORY_SEPARATOR && CCSubStr($TempFolder, -1) != "/" && CCSubStr($TempFolder, -1) != "\\") $TempFolder .= DIRECTORY_SEPARATOR;
$TempFileName = $TempFolder . "pdf" . session_id() . mt_rand(100000, 999999) . ".html";
$ResultFileName = $TempFolder . "pdf" . session_id() . mt_rand(100000, 999999) . ".pdf";
$WindowsQuote = DIRECTORY_SEPARATOR == "\\" ? '"' : "";
if ($TempFileName && $TmpFH = @fopen($TempFileName, "wb")) {
fwrite($TmpFH, $main_block);
fclose($TmpFH);
$Options = str_replace("{InputFile}", escapeshellarg($TempFileName), $Options);
$Options = str_replace("{Root}", escapeshellarg(getcwd()), $Options);
if (strpos($Options, "{ResultFile}") !== false && !file_exists($ResultFileName)) {
$Options = str_replace("{ResultFile}", escapeshellarg($ResultFileName), $Options);
exec($WindowsQuote . $Command . " " . $Options . $WindowsQuote);
if ($fh = @fopen($ResultFileName , "rb")) {
$now = time();
$ServerDate = gmdate("D, d M Y H:i:s", $now) . " GMT";
$ExpireDate = gmdate("D, d M Y H:i:s", $now + 60) . " GMT";
Header("Cache-control: ");
Header("Pragma: ");
Header("Date: " . $ServerDate);
Header("Expires: " . $ExpireDate);
Header("Content-Type: application/pdf");
while($str = fread($fh, 1024)) echo $str;
fclose($fh);
unlink($ResultFileName);
$Page_BeforeOutput = false;
}
} elseif ($fh = popen($WindowsQuote . $Command . " " . $Options . $WindowsQuote, "rb")) {
$firstPass = true;
while($str = fread($fh, 1024)) {
if ($firstPass) {
$now = time();
$ServerDate = gmdate("D, d M Y H:i:s", $now) . " GMT";
$ExpireDate = gmdate("D, d M Y H:i:s", $now + 60) . " GMT";
Header("Cache-control: ");
Header("Pragma: ");
Header("Date: " . $ServerDate);
Header("Expires: " . $ExpireDate);
Header("Content-Type: application/pdf");
$firstPass = false;
}
echo $str;
}
pclose($fh);
$Page_BeforeOutput = false;
}
unlink($TempFileName);
}
}
//End Convert Page to PDF
Any help would be greatly appreciated!!!
|