Help with mail_to variable

Hi There

Please can someone help me out with a bit of code.

I have a pdf report made from a form for jobcards which calls info from customers table, vehicles table and services table and then calculates totals and then saved as a record in my jobcard table.

At the top of the toolbar i have a “invoice pdf” button which just generates a pdf report from the jobcard form and opens to a browser window.

I copied the pdfreport and renamed it with a sub_email and inserted the sc_pdf_output macro which creates a pdf of the inovice to my local server, and then on scriptinit i run the sc_mail_send with attachment.

which works perfectly and sends the pdf invoice to the email address stipulated in the the sc_mail_send, $mail_to field.

However, i want to send the pdf to email stipulated in the customer email field for the relevant job.

The report form is setup to request the jobcard id to be enetered as it is linked to the jobcard form. I’m just not sure how to retrieve the customer email field and send it to, when hitting the “email PDF invoice” button to the customer.

How are you sending the email via simple sc_send or the mail api?

Simple mail, with attachment,

here is my code on pdf_report, Events>Onscriptinit:

/**

  • Send an email with attachment
    */
    // Email parameters
    $mail_smtp_server = ‘mail.domain.com’; // SMTP server name or IP address
    $mail_smtp_user = ‘email@domain.com’; // SMTP user name
    $mail_smtp_pass = ‘PaDdfvwfwe’; // SMTP password
    $mail_from = ‘email@domain.com’; // From email
    $mail_to = {customeremail}; // To email
    $mail_subject = ‘Invoice from Company’; // Message subject
    $mail_message = 'Hi! thanks so much for using our services, please find attached invoice, '; // Message body
    $mail_format = ‘T’; // Message format: (T)ext or (H)tml
    $mail_copies = ‘’; // List of the emails that will recieve the message
    $mail_tp_copies = ‘’; // Type copies: BCC (Hiden copies) or CCC (Regular copies)
    $mail_port = ‘587’; // Server port
    $mail_tp_connection = ‘N’; // Connection security (S) or (N)
    $mail_attachments = array(‘c:\invoices\file.pdf’); // List of attached files (located on the web server)

// Send email
sc_mail_send($mail_smtp_server,
$mail_smtp_user,
$mail_smtp_pass,
$mail_from,
$mail_to,
$mail_subject,
$mail_message,
$mail_format,
$mail_copies,
$mail_tp_copies,
$mail_port,
$mail_tp_connection,
$mail_attachments);

Code on pdf_report layout pdf>code:
/------------------ Page 1 -----------------/
sc_pdf_print($cell_id);
sc_pdf_print($cell_date);
sc_pdf_print($cell_time);
sc_pdf_print($cell_customerid);
sc_pdf_print($cell_vehicleid);
sc_pdf_print($cell_serviceid);
sc_pdf_print($cell_addon1id);
sc_pdf_print($cell_addon2id);
sc_pdf_print($cell_addon3id);
sc_pdf_print($cell_addon4id);
sc_pdf_print($cell_total);
sc_pdf_print($cell_endtime);
sc_pdf_print($cell_paymentmethod);
sc_pdf_print($cell_stage);
sc_pdf_print($cell_customerphone);
sc_pdf_print($cell_customeremail);
sc_pdf_print($cell_BusinessName);
sc_pdf_print($cell_BusinessReg);
sc_pdf_print($cell_Vat);
sc_pdf_print($cell_businessaaddress);
sc_pdf_print($cell_landline);
sc_pdf_print($cell_Profilename);
sc_pdf_print($cell_profilenumber);
sc_pdf_print($cell_profileemail);
sc_pdf_print($cell_profilereg);
sc_pdf_print($cell_profilewebsite);
sc_pdf_print($cell_profilebuilding);
sc_pdf_print($cell_profilesuburb);
sc_pdf_print($cell_profilecity);
sc_pdf_print($cell_profileprovince);
sc_pdf_print($cell_profilcecode);
sc_pdf_print($cell_88);
sc_pdf_print($cell_BankName);
sc_pdf_print($cell_AccountName);
sc_pdf_print($cell_AccountNumber);
sc_pdf_print($cell_BranchCode);
sc_pdf_print($cell_Reference);
sc_pdf_print($cell_ServicePrice);
sc_pdf_print($cell_addon1price);
sc_pdf_print($cell_addon2price);
sc_pdf_print($cell_addon3price);
sc_pdf_print($cell_addon4price);
sc_pdf_print($cell_xlprice);
sc_pdf_print_html($cell_JobNotes);
sc_pdf_output(‘c:\invoices\file.pdf’, “F”);

So it sends the geenrated pdf invoice fine to the email i set under $mail_to but i cant send it to the “Customeremail” setting.

Hi I was looking at some of my old pdf reports to find the answer, I abandoned the pdf reports because they were just to finicky however… I believe the below information should make it work for you.

It appears your variable field {customeremail} sc_pdf_print($cell_customeremail); is being loaded when running the report? if you echo the variable {customeremail} and turn on debug mode under application settings… If so take your mail settings and put into the onrecord event.

I have also have had to covert the email to string $customeremail = {customeremail}; for some circumstances.

If you want to use Onscriptinit I believe you will need to pass the {customeremail} to the pdf record ->[customermail] swift Mail can be finicky I would covert it $customermail = [customermail] ;

Events-Onscriptinit

$customermail = [customermail] ;
// To email
/**

  • Send an email with attachment
    */
    // Email parameters
    $mail_smtp_server = ‘mail.domain.com’; // SMTP server name or IP address
    $mail_smtp_user = ‘email@domain.com’; // SMTP user name
    $mail_to = $customermail;

I am not sure how long you have been using scriptcase but Personally I had many issues with pdf reports and spend countless times with editing and fixing them. I ended up going with custom html in the grid app. Its much more versatile in my opinion from creating pdfs and html emails

1 Like

Thanks So much!

running it on event> record, i added the customeremail variable and it works perfectly, sending with both api and normal smtp send, however it seems to be sending the old pdf report stored on the server location path and only generating a new one after… not sure what to change. is there a way i can generate the SC_pdf_output before the email? becuase that line generates and stores it on the server path for attachments to locate and attach.

hi there, hoping to see if anyone can assist, been trying everything and nothing seems to be working, Please can someone from scriptcase help.

I would then use two apps. 1st one as is with the pdf. Move the simple mail over too a blank app. when the pdf is generated then us a scredir over to the blank app that will send the mail and call for the new pdf. dose that make since?

thanks! i tried it, but i think i need a little more help. When i used sc_redir(blank send app); on any of the events, it doesnt seem to pass the customer email variable to the blank application to send.
I can go to navigation controls on the pdf report and se the exit link to the blank app with this code:

indent preformatted text by 4 spaces

$check_sql = “select customeremail FROM jobcard WHERE id = [jobcard]”;

sc_lookup(rs, $check_sql);

if (isset({rs[0][0]})) // Row found
{
$mail = {rs[0][0]};

}
else // No row found
{

$mail = 0;

}
sc_alert($mail. ’ ’ .[jobcard] );
if($mail!=0)
{
$rs = sc_send_mail_api(array(
‘profile’ => ‘’,

	'settings' => [
			'gateway'       => 'smtp',
			'smtp_server'   => 'mail.test.com',
			'smtp_port'     => '587',
			'smtp_user'     => 'mail@test.com',
			'smtp_password' => '1234',
			'from_email'    => 'vmail@test.com',
			'from_name'    => 'mail@test.com',
	],
'message' => [
		'html'          => 'Hi! thanks so much for using our services, please find attached invoice',
		'text'          => '',
		'to'            => $mail,
		'attachments' => array('C:/Program Files/NetMake/v9-php81/wwwroot/scriptcase/file/doc/test.pdf'), 
		'subject'       => 'Your subject'
	]

));

if($rs){
sc_alert({lang_mail_sended_ok} );
}
else
{
sc_error_message({sc_mail_erro});
}
}

The email sends with the correct attachment, but i get an error that it could convert to string:

Fatal error: Uncaught Error: Object of class grid_jobcard_ini could not be converted to string in C:\Program Files\NetMake\v9-php81\wwwroot\scriptcase\app\Vayaserv_V1\grid_jobcard\grid_jobcard_grid.class.php:9342 Stack trace: #0 C:\Program Files\NetMake\v9-php81\wwwroot\scriptcase\a…