Thanks for your advice cfstarlight, I tried the basics, its sending the emails fine, to the right customers also, its just not changing the image for each company im in. even though I dump out the values of the templates it giving me the correct ones. but then when I press submit to send all emails it goes back to putting the same image on all PDF’s
I even tried hard coding the image into here:
image = "#request.mainfilePath#templates\\#image = "#request.mainfilePath#templates\\#qgetcreditnotetemplate.InvoiceTemplate_FileName#".InvoiceTemplate_FileName#"
and it works fine it uses that image, but when I link back up to my Query it gives one image for all if that makes sence
and the query “qgetcreditnotetemplate” is correct as I said above when I dump out the values if it, Its outputting the correct Images
Everything works right up until the image is added to the PDF
I think I might have to do what downtroden has suggested and Create the pdf then send the email.
<!--- Count the Emails as they are sent --->
<cfquery name="qgetemailcount" datasource="#request.dsn#">
select INVOICEEMAILLOG_Key
from INVOICEEMAILLOG IE
where INVOICE_Key = INVOICE_key
AND INVOICEEMAILLOG_Type = 1
</cfquery>
<cfmail query="Getemails"
from="#Company_Email#"
to="#Customer_Email#"
subject="#COMPANY_Name# Invoice Number: #INVOICE_Number#"
replyto="#Company_Email#">
<cfquery name="qaddintolog" datasource="#request.dsn#">
insert into INVOICEEMAILLOG
(INVOICEEMAILLOG_To,INVOICEEMAILLOG_Replyto,INVOICE_Key,INVOICEEMAILLOG_Type)
values
<!--- Set InvoiceEmailLog to 1 for emailing --->
<cfset INVOICEEMAILLOG_Type = 1>
('#Customer_Email#','#Company_Email#','#INVOICE_Key#','#INVOICEEMAILLOG_Type#')
</cfquery>
Dear #Customer_DelvName#
Please see attachment below
<cfquery name="qgetinvoice" datasource="#request.dsn#">
select INVOICE_PDFFile
from INVOICE I, COMPANY C, CUSTOMER CU, InvoiceTemplate IT
where I.Company_Number = C.COMPANY_Number
AND I.CUSTOMER_AccNum = CU.CUSTOMER_AccNum
AND IT.Company_Number = I.Company_Number
AND IT.Company_Number = I.Company_Number
AND IT.InvoiceTemplateType_Key = I.InvoiceTemplateType_Key
AND CU.CUSTOMER_DelvNum = I.CUSTOMER_DelvNum
AND I.INVOICE_Number = #INVOICE_Number#
AND CU.Customer_Email <> ''
</cfquery>
<cfset timestamp = timeformat(now(),"HHmmss")>
<cfset pdfname = INVOICE_Key&"_"×tamp&".pdf">
<cfpdf action="getinfo" name="pdfinfo" source="#request.mainfilePath#PDFs\\#qgetinvoice.INVOICE_PDFFile#">
<cfif pdfinfo.TotalPages gt 1>
<cfset totalpages = "1-"&pdfinfo.TotalPages>
<cfelse>
<cfset totalpages = 1>
</cfif>
<!--- Get the template for the Invoices --->
<cfquery name="qgetcreditnotetemplate" datasource="#request.dsn#">
select InvoiceTemplate_FileName
from InvoiceTemplate IT, INVOICE I, COMPANY C, CUSTOMER CU
where I.INVOICE_Key = I.INVOICE_Key
AND I.Company_Number = C.COMPANY_Number
<cfif isdefined ('form.DateFrom')>
AND I.COMPANY_Number = #form.COMPANY_Number#
AND IT.InvoiceTemplateType_Key = I.InvoiceTemplateType_Key
AND IT.Company_Number = I.Company_Number
AND I.CUSTOMER_AccNum = CU.CUSTOMER_AccNum
AND I.CUSTOMER_DelvNum = CU.CUSTOMER_DelvNum
AND CU.Customer_Email <> ''
<cfif isdefined ('form.DateFrom')>
<cfif form.DateFrom neq ''>
</cfif>
</cfif>
</cfif>
</cfquery>
<cfpdf
action = "addwatermark"
source = "#request.mainfilePath#PDFs\\#qgetinvoice.INVOICE_PDFFile#"
image = "#request.mainfilePath#templates\\#qgetcreditnotetemplate.InvoiceTemplate_FileName#"
foreground = "No"
overwrite = "yes"
pages = "#totalpages#"
opacity = "10"
Position = "10, -50"
showonprint = "YES"
destination = "#request.maindrivePath#temppdf\\#pdfname#">
<cfmailparam file="#request.maindrivePath#temppdf\\#Invoice_Key&"_"×tamp&".pdf"#" type="application/JPG">
Regards,
#Company_Name#
#Company_Address1#, #Company_Address2#
#Company_Address3#, #Company_Address4#
#Company_Phone#, #Company_Fax#
</cfmail>