Forums

Dynamic reply-to, Joomla email added to reply-to in email

Uclabruins 15 Nov, 2011
I'm using Chronoforms V4 RC2 with Joomla 1.7

I'm trying to set the dynamic reply-to address for the email function. When I do so, it sets the correct field as the reply-to address, but it also adds the Joomla site email address to the beginning of the reply-to (so it will reply-to two different email addresses: the Joomla Site email address and the form submitter's email address).

Under "static" I have "to", "from name", and "from email" filled in. Both of those email addresses end in our site domain. Under dynamic, I have "subject", "reply to name", and "reply to email" filled in.

All I'm trying to do is have a contact form that submits tickets into our help desk (Kayako). So, if we could do it another way, or, if it's not possible to get rid of the Joomla email in reply-to, if we could have the dynamic reply-to from the form show up before the Joomla site address in the reply-to box, that should work.
GreyHead 15 Nov, 2011
Hi Uclabruins ,

I think this is a Joomla! 'feature', though thre may be a fix in ChronoForms. I recall a thread about it a few weeks ago but I don't remember if there was a fix :-(

Bob
GreyHead 16 Nov, 2011
Hi Uclabruins,

I tracked this down. It's a Joomla! problem and can't be reolved in ChronoForms as far as I can see. The version of PHP Mailer has a 'auto' option in the function that adds From Email addresses if it is set to 'true' - which is the default setting - then the From Address is copied to the Reply To address.

The Joomla! sendMail function takes no account of this so auto remains 'true'. You can fix it by editing libraries/joomla/mail/mail.php file. Look for this function around line 83 and edit the two marked lines by adding , false to each of them as shown here
	/**
	 * Set the email sender
	 *
	 * @param   array  email address and Name of sender
	 * <code>array([0] => email Address [1] => Name)</code>
	 *
	 * @return  JMail  Returns this object for chaining.
	 *
	 * @since   11.1
	 */
	public function setSender($from)
	{
		if (is_array($from)) {
			// If $from is an array we assume it has an address and a name
			$this->SetFrom(JMailHelper::cleanLine($from[0]), JMailHelper::cleanLine($from[1]), false); // << edit this line
		}
		elseif (is_string($from)) {
			// If it is a string we assume it is just the address
			$this->SetFrom(JMailHelper::cleanLine($from), '', false); // << edit this line
		}
		else {
			// If it is neither, we throw a warning
			JError::raiseWarning(0, JText::sprintf('JLIB_MAIL_INVALID_EMAIL_SENDER', $from));
		}

		return $this;
	}

Bob
nfaustino 18 Nov, 2011
Hi.
I had the same problem and was resolved.
Thanks GreyHead.
Only one small detail:
the path is "libraries/joomla/mail/mail.php" and not "librairies/mail/mail.php" I think.

Thanks
GreyHead 24 Nov, 2011
Hi nfaustino,

Thanks - I've updated my post to correct the path.

Bob
jllav03 24 Jan, 2012
Chronoform question related to this topic, V3:

Can I add more than (1) Dynamic Subject under the Setup Email tab? If so, what is the syntax? I tried the following but it didn't work:

dmfilename, catid
Max_admin 29 Jan, 2012
Hi jllav03,

No you can't because every email has 1 subject only, the question is actually off topic and is not matching the forum category, if you have more questions then please start a new topic under the correct forum.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 03 Feb, 2012
Hi,

There's a partial fix for this bug in Joomla! 2.5 . . . but it hasn't been carried through to the sendmail function so ChronoForms still can't access it (at least not without building it's own sendmail function).

There is a hack for this. Edit the libraries/joomla/mail/mail.php file in Joomla! 2.5 or later. Look for this function around line 411 and make the two changes shown:
	public function sendMail($from, $fromName, $recipient, $subject, $body, $mode = 0, $cc = null, $bcc = null, $attachment = null, $replyTo = null,
		$replyToName = null)
	{
		// $this->setSender(array($from, $fromName)); // comment out this line
		$this->setSubject($subject);
		$this->setBody($body);

		// Are we sending the email as HTML?
		if ($mode)
		{
			$this->IsHTML(true);
		}

		$this->addRecipient($recipient);
		$this->addCC($cc);
		$this->addBCC($bcc);
		$this->addAttachment($attachment);

		// Take care of reply email addresses
		if (is_array($replyTo))
		{
			$numReplyTo = count($replyTo);

			for ($i = 0; $i < $numReplyTo; $i++)
			{
				$this->addReplyTo(array($replyTo[$i], $replyToName[$i]));
			}
		}
		elseif (isset($replyTo))
		{
			$this->addReplyTo(array($replyTo, $replyToName));
		}
// add these lines from here
		if ( count($this->ReplyTo) > 0 ) {
			$this->setSender(array($from, $fromName, false));
		} else {
			$this->setSender(array($from, $fromName));
		}
// to here
		return $this->Send();
	}

Bob
GreyHead 22 Apr, 2012
Hi,

I found a fix for this problem at long last. SendMail is now deprecated in Joomla! and wile it still works it hs this little bug which is unlikely to be fixed.

The replacement for sendmail is:
$mail = JFactory::getMailer();
$mail->sendMail(. . .);
with the same parameter set as before.

I have updated my custom Email [GH] action to use this code and so far it seems to be working well.

Bob
jwill 06 May, 2012
Bob,

I guess I came late to the party, I waited until my migration to Joomla 2.5 before installing V4. I could do just about everything I wanted to with the previous version. Your book helped a lot. I hope you are going to write a V4 book covering the same subjects you covered with V3 because I'm finding I can't do much of anything anymore.

I created a simple contact form but I can't make the reply to work (I read this topic and another on the subject.) It has me very confused.

I have the following questions:

You stated that "SendMail is now deprecated in Joomla!". Usually if something is deprecated, it is because another method is preferred. If this is the case, what does the Joomla team recommend in place of Send Mail? I noticed I had PHP Mail selected in Global Configuration, but I get the same result with both of them.

You provided a code modification designed to overcome the problem, but this modification would have to be carried forward with every upgrade making it a little cumbersome.

Finally, you provided your custom Email [GH] action. If I understand right, the code modification should not be needed with this action. I downloaded and installed the action but replies are still going to both the dynamic address and the from address. Am I missing something in the setup (it looks pretty straight forward so I don't know where I could have gone wrong.)

Any guidance you can give me will be appreciated.
GreyHead 06 May, 2012
Hi jwill,

Sorry for the confusion :-( I may have skipped a few steps and jumped to some conclusions based more on wishful thinking than on the code :-( That said that code is very interlinked and it's hard to track through exactly what is going wrong here.

The sendMail() I'm referring to is the specific way of calling the Joomla! sendMail() method using JUtility::sendMail() in the standard ChronoForms Email action. This is how it used to work in previous versions of Joomla!.

If go and look in the JUtility file (libraries/utililities/utility.php) you'll find this code around line 45
// Deprecation warning.
JLog::add('JUtility::sendmail() is deprecated.', JLog::WARNING, 'deprecated');
I stumbled across this by chance whilst trying to find a fix for the bug. I guess that I should spend more time studying my Joomla! logs :-(

The new preferred way to call the same sendMail method is through the code I posted.

Looking at it today I'm finding it harder to see that the change does actually make any difference. Though when I tested it last time is appeared to.

Disappointing . . . it looks as though the bug is still there; and, as you say, needs to be fixed in the Joomla! core code :-( I have reported it a while ago but that usually has little effect.

The only alternative that I can see at the moment is to build a modified version of the sendMail() method.

Maybe when I voem back from my trip next week I'll take a look . . .

Bob

PS I'm slowly gathering material to write a new version of the book but still a long, long way to go.
This topic is locked and no more replies can be posted.