Topic: email of quotes

I am still working on handling quotations.  My latest problem is emailing a quotation to a customer.

I have a customer salesquotation (as suggested by Joe) and have created branches as I need to make quotations.
The branches that I create have 'Contact active for:' set to be General.  According the the wiki, that should get the quotation emailed to the branch.  But when I try to send email, I get the error:  'You have no email contact defined for this type of document'.

If I edit that branch and make the Contact active for: = Order, the email is sent.  Why is the email giving any error when only General is set?

I am using version 2.3.13 on Ubuntu 12.04LTS.



Re: email of quotes

An error happened when implementing the email of sales document.

In /reporting/rep111.php, line 83 
    $contacts = get_branch_contacts($branch['branch_code'], 'order', $branch['debtor_no'], false);

The last parameter in get_branch_contacts should be true

    $contacts = get_branch_contacts($branch['branch_code'], 'order', $branch['debtor_no'], true);

You can look up this function call in rep109.php, rep110.php, rep111.php nd rep113.php and change the last paraameter to true.

These change has been changed in the HG repository.

Thanks for pointing this out!


Re: email of quotes

Hi Joe:

Thanks for the fix. 

Two questions.

Where do I find the text that is used for the subject, any signature, from,  etc for the email?  Wiki?

Would it be possible to get some help on how to use Mercurial to keep up with these changes on my local box.  Since some of the base files get changed on local box such as,, and as examples.  The changes in those files are changing text in reports.  What I can't work how is how to get into my local FA the changes that are made to them in the basic code and up in the update versions and still keep my text editing changes. 

Same kind of deal with the reports that I have in /company/0.  For example, I have some changes in rep109 and so it is in company dir, but the ver13 t0 ver14 made changes in rep109 under reporting dir. 

I need some kind of scheme to control the changes.  I am sure I am not the only one needing this.  A wiki would sure be nice.

Thanks again for the quick fix.


Re: email of quotes

If you are looking for easy way for maintaining local patches on top of latest FA, you should simply use mercurial. Just clone sourceforge repository on your development box and  maintain your local changes in separate branch e.g.:

hg clone
hg branch local_branch

Then apply all your local patches, and save the changes:

hg commit -m "my local patches"

When new changes appears in repo and you want to update your local_branch:

hg pull
hg checkout local_branch
hg merge default

When no conflicts happen between your changes and chnages in repo you are done. Otherwise you have to resolve conflicts and commit the effect of merge to the local_branch (more details about how to resolve the conflicts you will find in google).

Re: email of quotes

Thanks Janusz:

I will try it out this weekend.

Not sure how this works with the files in the company directory.  They aren't changed as I understand it, because the is where we put the reports that we have modified.  So if I have a report rep109 in company and rep109 gets changed in the sourceforge repository, seems there would be no change or conflict in the company file or am I just not understanding something?  I sort of thought that for there to be anything to merge there had to be two commits that included some of the same files?

I am pretty easy to confuse.



Re: email of quotes

Yes, if you only use the possibility to keep your own report version in company folder, you even do not need mercurial. But AFAIR you have talked about some other customizations (added links on final transaction page) in another thread. The described worflow should make your life  easier in this case.
Regarding the company folder you can easily remove the company folder from Mercurial version control in your local_branch to be on safe side.

Re: email of quotes


Thanks for you reply, as always very helpful and on point. 
I guess the only way that I can get the rep109 in company dir to have the new changed from the reporting dir as in ver .14 would be to use something like Meld for each repxxx in company dir?  That is what I did for ver .14 a few days ago and worked ok.  Just didn't know if there is a better way.  I will test Mercurial this weekend and see if I can do it properly.


Re: email of quotes

Yes, this is the right way.

Re: email of quotes

Hi all:

I am still working on getting quotes to email properly.  My problem right now is that the email is sent out with the From:  It needs to be where myuser is the person who is logged in to FA and doing the email.  This seems to be the reasonable way it should be.  I know that the email is using the file  /etc/mailname (in Ubuntu 12.04) to get  I just can't figure out where the www-data comes from. I know that www-data is the apache2 user, but don't understand how that works with FA.  How do I get the user name in the From: as I want it?



10 (edited by apmuthu 01/31/2013 08:59:14 pm)

Re: email of quotes

Anyone integrated PHPMailer in the place of the existing ? This will enable sending using a relay SMTP server like gmail. is called and instantiated only in sales/includes/db/ and reporting/includes/ Hence such integration with PHPMailer would be easy.

Lines 994-996 in reporting/includes/

                        $mail = new email(str_replace(",", "", $this->company['coy_name']),
                        $mail->charset = $this->encoding;

Line 104 in sales/includes/db/

        $mail = new email($company['coy_name'], $company['email']);

The charset is missing and the coy_name is not stripped of commas in the latter case.

The latter should be:

$mail = new email(str_replace(",", "", $this->company['coy_name']),    $this->company['email']);

Better still would be to move the stripping of the commas to the class method constructor itself by inserting the following in line 47 of reporting/includes/

$name = str_replace(",", "", $name);

and removing the str_replace from both files that use the class.

Re: email of quotes

Hi apmuthu:

I really do not understand what your code does.  I understand what str_replace does, I use it on several of my php  pages on my website.  I just don't know what it does to get what I want to do on the emails done.  How does that get the From: for the email set to be instead of


12 (edited by apmuthu 02/01/2013 07:41:11 am)

Re: email of quotes

It is possible that the comma may be a delimiter somewhere and may need to be stripped out of the Name. Also was checking for consistency and alternatives to the existing mailer like the integration in similar context.

For your specific requirement, you may want to dump the variables just before the send() occurs in both the caller instance and in the class method as well.

Re: email of quotes

Hi apmuthu,

I did:  Better still would be to move the stripping of the commas to the class method constructor itself by inserting the following in line 47 of reporting/includes/   $name = str_replace(",", "", $name);

The email still gets sent From: and not
So no gain yet.


Re: email of quotes

Maybe I am not being clear on what I need.  The 'from' I am talking about is not what shows up on the from when you just look to see where the email is from but the Return Path you see when you look at the header source. In this case, it is Return-Path: <>.

The problem is since www-data is not a user on the smtp server the email will not be fwd and it is just dumped. So it needs to be one of our users, for example

Maybe this help explain my problem.


15 (edited by ed10 02/01/2013 10:44:34 pm)

Re: email of quotes

I have the Return Path fixed.  Now my quotation emails are going out to customers. 

My next problem is in in around line 1020:
  $sender = $this->user . "\n" . $this->company['coy_name'] . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone'];

This adds sort of a signature to the email.  $this->user is empty so I have just a blank line where the user should be.  I can't figure out how/where it gets populated.  All the rest of the sig is correct and as it is supposed to be.  Customer just doesn't know which salesperson sent the email.

The line in the source of the email I am looking at is:  From: <>
I think it is supposed to be more like:  From: sally <>

Then the name will be in the sig also.


16 (edited by apmuthu 02/02/2013 09:08:23 am)

Re: email of quotes

How did you fix the return path? Was it the addition of a reply-to header in the script or in the ?

$this->user is the currently logged in user whose email should be in the users table.

Re: email of quotes

In I set this around line 42:
var $add_params = '-f';

I am using postfix on ubuntu 12.04 and the -f flag sets the 'reply to' in postfix.

If $this->user is the currently logged in user, why is it not in the sig created by the line of code:
$sender = $this->user . "\n" . $this->company['coy_name'] . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone'];

Every user has an email in the user table and you can't send an email w/o being logged on, but $this->user is sure empty.  I don't have any idea how to fix this. Is user a global variable?  How can I display all the global vars set in FA?


18 (edited by apmuthu 02/02/2013 03:36:40 pm)

Re: email of quotes

From the PHP mail() manual:

$to      = '';
$subject = 'the subject';
$message = 'hello';
$headers = 'From:' . "\r\n" .
    'Reply-To:' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

If the $this->user correctly enters the from header variable, it can be made to enter the same value into a $reply-to variable and used as above.

There is a $sender variable that gets populated as well?
Or just use the from header directly for the 'Reply-to' header.

Re: email of quotes

again, I am confused.  $this->user is empty, blank.  when  $this->user . "/r/n"  is done, I get a blank line

20 (edited by apmuthu 02/02/2013 03:35:31 pm)

Re: email of quotes

Line 47 of reporting/includes/

$this->header = "From: $name <$mail>\n";

may be replaced with:

$this->header = "From: $name <$mail>\nReply-to: $name <$mail>\n";

The $add_params variable in the file remains unused. Quote from the PHP manual for mail():

additional_parameters (optional) : The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.
The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.

The $this-user in the other files may have an issue of scope of being an included file's variable.

Re: email of quotes

I have the from and reply to working just fine.  The problem I am having now is $this->user is empty and i don't know why or how to fix it.

22 (edited by apmuthu 02/02/2013 04:05:27 pm)

Re: email of quotes

Line 269 in reporting/includes/, the function Info() sets:

$this->user = $_SESSION["wa_current_user"]->name;

Since it is taken from session variable, and the function Info() is not called anywhere within the FrontReport class at all, it is called by it's instance in each report.

Each report file repXXX.php has some function(s) that make an instance like $rep = new FrontReport(.... followed by $rep->Info($params, $cols, $headers, $aligns); This will set the $user FrontReport class variable

The FrontReport class method End() in lines 993-995 includes:

require_once($path_to_root . "/reporting/includes/");
mail = new email(str_replace(",", "", $this->company['coy_name']),

This method End() is called at the very end of each repXXX.php file.

All seems fine and hence the syntax to set the $this->user is wrong.

includes/ provides the correct syntax:

$user = $_SESSION["wa_current_user"]->user;

Therefore Line 269 in reporting/includes/ should be::

$this->user = $_SESSION["wa_current_user"]->user;

Re: email of quotes

that is close, that gives the 'id' of the user rather than the 'user_id'.

24 (edited by apmuthu 02/02/2013 05:21:51 pm)

Re: email of quotes

The said variable:
appears in:


A few months ago, some repeating code in all the renderer.php files were siphoned out elsewhere to a single function and at that time the variable may have vanished from being set or when changes to includes/ were made over time.

Therefore while retaining the variable $_SESSION["wa_current_user"]->name in the said files, it may be required to set the field real_name from the users table if the user is logged in - in the includes/ file.

Come to think of it, thereal_namein theuserstable does not seem to be used anywhere! Optional field that may not have any value at all!

25 (edited by ed10 02/02/2013 04:56:07 pm)

Re: email of quotes

i got the user name by changing:
$this->user = $_SESSION["wa_current_user"]->user;
$this->user = $_SESSION["wa_current_user"]->username;

Isn't it used when you show the users who are logged in at the bottom of the pages?