Mail headers

Discuss everything related to FormBuilder. All versions. Any questions related to the FormBuilder developing or using should be posted to this forum.

Moderators: alexandrleonenko, goas

lapuella
Junior
Junior
Posts: 11
Joined: Sep 12th, '13, 18:08

Mail headers

Postby lapuella » Sep 12th, '13, 18:16

I would like to add mail headers (From:, Reply-to etc.) to a form created with Formbuilder. Is this possible? Otherwise there is no sender visible in the mail.

goas
Newbie
Newbie
Posts: 9
Joined: Apr 23rd, '12, 11:26

Re: Mail headers

Postby goas » Sep 16th, '13, 10:58

To add emal headers you should do as follows:

Code: Select all

$form->getEmail()->SetFrom($from);

where $form is your form object, and $from is value for a from header.

lapuella
Junior
Junior
Posts: 11
Joined: Sep 12th, '13, 18:08

Re: Mail headers

Postby lapuella » Sep 17th, '13, 01:02

Thank you.
But I don't understand it yet.

First I tried:
$from = "info@company.com";
$form->getEmail()->SetFrom($from);

That doesn't work.

Then I tried:

$from = 'MIME-Version: 1.0' . "\r\n";
$from .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$from .= 'From: Name Company <info@company.com>' . "\r\n";

$form->getEmail()->SetFrom($from);

But it is not working either.

Then I tried:

$form->AddHeader('<h2>Title</h2>')
->SendResultAsEmail(1)
->AddEmailAddress('info@company.com')
->getEmail()
->SetFrom('info@company.com');

I'm getting a warning (Fatal error: Call to undefined method FB_Form::SetFrom())

How do I define $from in a correct way?

Thank you for any help you can provide in this situation.

goas
Newbie
Newbie
Posts: 9
Joined: Apr 23rd, '12, 11:26

Re: Mail headers

Postby goas » Oct 16th, '13, 20:40

So sorry, I've missed your message! Well, the first thing you did is supposed to work. I'll try it once more myself and let you know the result tomorrow.

extremecorp
Newbie
Newbie
Posts: 7
Joined: Mar 8th, '10, 09:20

Re: Mail headers

Postby extremecorp » Nov 21st, '13, 03:23

I had exactly the same problem trying to get the "from" to say anything besides a blank.

I suspect it may have something to do with the fact DataValidator v2.03 not working with FormBuilder 2.01, and reverting to DV v1?

extremecorp
Newbie
Newbie
Posts: 7
Joined: Mar 8th, '10, 09:20

Re: Mail headers

Postby extremecorp » Nov 21st, '13, 03:40

Found the problem! The "from" function was never programmed into the script: /lib/classes/basic/FB_Form.class.php

which is the one used to take the form submission and send via e-mail.

Admin - PLEASE FIX in v2.04? :)

administrator
Site Admin
Site Admin
Posts: 6011
Joined: Jan 7th, '09, 23:18
Contact:

Re: Mail headers

Postby administrator » Nov 21st, '13, 21:28

Changes:
in lib/classes/basic/FB_Letter.class.php

1. Change _SendLetter() method with following:

Code: Select all

    private function _SendLetter()
    {
        $headers  = "Content-type: text/html; charset=utf-8\r\n From: ".$this->from."\r\n X-Mailer: PHP/".phpversion();
        $props = "-f".$this->from;
        return mail($this->_GetLetterTo(), $this->letterSubject, $this->content, $headers, $props);
    }


1. Change SendLetter() method with following:

Code: Select all

    public function SendLetter(array $emailAddresses, $letterSubject, $from = '')
    {
        $this->emailAddresses = $emailAddresses;
        if(empty($this->letterSubject)){
            $this->letterSubject = $letterSubject;
        }
        $this->from = (!empty($from) )? $from : $this->from ;
        return $this->_SendLetter();
    }

lapuella
Junior
Junior
Posts: 11
Joined: Sep 12th, '13, 18:08

Re: Mail headers

Postby lapuella » Dec 1st, '13, 13:48

I changed the code in FB_letter_class.php, but still getting the error:
Fatal error: Call to undefined method FB_Form::SetFrom() in......

Is it possible that you post the code of a working example, so I can see what I am doing wrong?

administrator
Site Admin
Site Admin
Posts: 6011
Joined: Jan 7th, '09, 23:18
Contact:

Re: Mail headers

Postby administrator » Dec 2nd, '13, 07:29

Please re-download the latest version. Does it help?

goas
Newbie
Newbie
Posts: 9
Joined: Apr 23rd, '12, 11:26

Re: Mail headers

Postby goas » Dec 2nd, '13, 19:41

Method SetFrom() belongs to FB_Letter object, so to call it you need to get this object. You can get it with method $form->getEmail().


Return to “ApPHP FormBuilder {developers/users}”