Forums

Custom Mail Header

dimna 27 May, 2015
Hello,
is it possible to use Custom Mail Header in an email action?
I found this old post, but I am not sure where to insert the text
$mailer->AddCustomHeader("X-Custom-Header: The Value");

Thanks
GreyHead 27 May, 2015
Hi dinma,

Not using the Email action as far as I know; and it doesn't look as though the Joomla! JMail class handles it either.

You can do it using your own PHP in a Custom Code action - see the post you found for a version of the code to do that.

Bob
dimna 28 May, 2015
Hello,
thank you for your answer.

I forgot the link to the old post. Here it is:
http://www.chronoengine.com/forums/posts/f2/t14566.html

Using a Custom Code Action, I have do code everything myself, is this right?
Is there anywhere an example how I can attach files and build the body?



For example I am not sure how to do this:

...
$mailer->addAttachment($attachment);
...

Can I find a filename of an Fileupload action like this:

$mailer->addAttachment($form->NameOfTheFormField);



Kind regards
astrid
GreyHead 29 May, 2015
Hi dimna,

What do you actually need to do here? just curious as there may be another way round.

You can access the form data from the $form->data array as $form->data['NameOfTheFormField']

Bob
dimna 03 Sep, 2015
Hello Bob.

Sorry for not answering such a long time, but I have had other problems and now I have to come back to this issue again.
Perhaps I explained not correct what I want to do? I will try again more precisely.
I have a form that sends the content to a ticket system. This ticket system can sort the ticket with the help of Custom Mail Headers.
For example, if I add

…
$mailer =& JFactory::getMailer();
…
$mailer->AddCustomHeader("X-OTRS-Queue: NameOfTheQueue");
…


this email will put in the Queue NameOfTheQueue.


I like to use Chronoforms email action, but I didn’t know how to put in the Custom Mail Header.

I set up a little test form with only one field. I send this form and I see in the debug, that there are many other informations (to, subject, from name ...).

Array
(
    [4] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:test@webb.de
                    [2] => Subject:Test
                    [3] => From name:Test
                    [4] => From email:
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Body:
<table>
<tr><td>Custom Code</td><td></td></tr>
<tr><td>Textarea Label</td><td>Test</td></tr>
</table><br /><br />IP: ::1
                )

        )

)


How is it possible to use the Custom Header X-OTRS-Queue with the Chronoforms email action?

I understand that I have to use a Custom Code action. What do I have to put in this Custom Code action exactly?


Thank you very much for your help.
GreyHead 04 Sep, 2015
Hi Astrid,

As you saw before the ChronoForms Email action doesn't support custom headers. You can use a Custom Code action - as in the other thread you linked (code copied below) to so set up your own customised mailing code
<?
$mailer = \Factory::getMailer();
$mailer->setSender(array("from @[at] host [dot] com", "Fromname"));
$mailer->setSubject("Some Subject");
$mailer->setBody("The message body here... Might have to add fancy code to include form submitted data.");
//$recipient, $cc, $bcc may be either strings or arrays of strings containing recipient email addresses..
$mailer->addRecipient($recipient);
$mailer->addCC($cc);
$mailer->addBCC($bcc);
//$attachment may be either string or array of strings containing filename (with paths) of files to attach..
$mailer->addAttachment($attachment);
$mailer->addReplyTo(array("reply.to @[at] host [dot] com", "ReplyTo name"));
$mailer->AddCustomHeader("X-Custom-Header: The Value");
$mailer->send();
?>

You can add form values here here needed using $form->data['input_name'] and the path to an uploaded file should be available in $form->files['input_name']['path']

Bob
dimna 04 Sep, 2015
Thank you very much Bob. Now it is clear for me.
I will try it on Monday. I wish you a great weekend.
This topic is locked and no more replies can be posted.