Custom Mail Header Possible?

gdpodesta 02 Jun, 2009
Hello,
trying to get an "enhanced" support form working. Our ticket system is quite extensive, and apparently will only extract the customer number from a custom mail header. This appears to be a pretty big hack of Joomla1.5x, so was hoping/wondering/praying if this has been dealt with previously, or if anyone has any pointers on how they would add a custom header to the outgoing chrono email

Thanks in advance
nml375 02 Jun, 2009
Hi,
That shouldn't be hard, although perhaps not trivial. You'll need to drop CF's builtin emails+templates in favor of some manual labor (coding).

Roughly put, you'll need to use the JMail class, rather than relying on the JUtility::sendMail() function call done in CF.

A rough skeleton code would look like this:
<?
$mailer =& JFactory::getMailer();
$mailer->setSender(array("from@host.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@host.com", "ReplyTo name"));
$mailer->AddCustomHeader("X-Custom-Header: The Value");
$mailer->Send();
?>

Not all of those settings are needed, but any mail needs a sender, atleast one recipient, a body, and a subject.
The AddCustomHeader() method is part of the PHPMailer class, and is inherited by JMail.

The code is written from head/manpages, so I cannot warrant that it is free from bugs, just let me know if you get stuck anywhere in the process.

/Fredrik
gdpodesta 02 Jun, 2009
Ah....you're a saint....should be able to hammer this one out now that I have the best starting point.

Thanks!😀
aredfern 19 Jun, 2010
Hi

I found this post and it looks exactly what I need. I have a form set up that when submitted sends the email. I am trying to get the email to subscribe to a mailing list which it does but the mailing list uses the header information address (that is, the default site address) and not the email address captured in the form. How can I set up the header to include information from the form? I am not frightened to hack code but need to be pointed in the right direction.

Thanks for your help.
dubois09 20 Jun, 2010

Hi,
That shouldn't be hard, although perhaps not trivial. You'll need to drop CF's builtin emails+templates in favor of some manual labor (coding).

Roughly put, you'll need to use the JMail class, rather than relying on the JUtility::sendMail() function call done in CF.

A rough skeleton code would look like this:

<?
$mailer =& JFactory::getMailer();
$mailer->setSender(array("from@host.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@host.com", "ReplyTo name"));
$mailer->AddCustomHeader("X-Custom-Header: The Value");
$mailer->Send();
?>

Not all of those settings are needed, but any mail needs a sender, atleast one recipient, a body, and a subject.
The AddCustomHeader() method is part of the PHPMailer class, and is inherited by JMail.

The code is written from head/manpages, so I cannot warrant that it is free from bugs, just let me know if you get stuck anywhere in the process.

/Fredrik



Thanks a lot Fred, I've been looking for this answer also for weeks! You saved my site...
This topic is locked and no more replies can be posted.