I want to introduce the new feature which is setting the reply address or sender address when sending invoice mail, or an Ask_Question mail, etc. to the vendor.
You can enable this feature "Receive vendor mail with recipient address" via backend (default is off), so there is no side effect adding this feature. In addition you can choose between building a replyTo or definitely sender address with the next parameter "Recipient address set as Sender, not ReplyTo", but several Internet providers do not permit to set the Sender email address.
What does that mean?
- Usually, if somebody is buying a product, he/she will get an e-mail from the website. In addition, the vendor receives the order via e-mail (invoice).
The vendor gets this mail with sender (from) = Address of Joomla website , and address (To) = Address of Vendor;
With this feature on, you'll receive the vendor's e-mail with replyTo = Address of the recipient (the customer) OR with another flag set the sender (from) = Address of the recipient.
Be careful, switching on this feature! Several Internet provider do not allow setting this to another e-mail address as your own webserver e-mail address.
Now, let's start from 1.) to 3.)
1.) Language
=============
First of all, add the following lines to your language file (administrator): (I use English language at the backend only :-))
FILE: administrator/language/en-GB/en-GB.com_virtuemart.ini
COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_RECIPIENT="Receive vendor mail with recipient address"
COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_RECIPIENT_EXPLAIN="Usually the vendor receives the mail from joomla system email address. If you set this, you'll receive the mail coming as recipient address. Set this option if you're really sure what you do! If in doubt, do not switch on this parameter."
COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_SETSENDER="Recipient address set as Sender, not ReplyTo"
COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_SETSENDER_EXPLAIN="If set, the mail address of the recipient is set as Sender. If not, the recipient is set as reply address. Set this option if you're really sure what you do! If in doubt, do not switch on this parameter."
2.) Add new parameters to the backend's configuration
=======================================================
FILE: administrator/components/com_virtuemart/views/config/tmpl/default_shop.php (line 74)
Before:
<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FORMAT_HTML') ?>
</option>
</select>
</td>
</tr>
<?php /* <tr>
<td class="key">
<span class="hasTip" title="<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_DATEFORMAT_EXPLAIN'); ?>">
After:
<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FORMAT_HTML') ?>
</option>
</select>
</td>
</tr>
<tr>
<td class="key">
<span class="hasTip" title="<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_RECIPIENT_EXPLAIN'); ?>">
<label for="mail_from_recipient"><?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_RECIPIENT') ?></span>
</span>
</td>
<td>
<?php echo VmHTML::checkbox('mail_from_recipient', $this->config->get('mail_from_recipient',0)); ?>
</td>
</tr>
<tr>
<td class="key">
<span class="hasTip" title="<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_SETSENDER_EXPLAIN'); ?>">
<label for="mail_from_setsender"><?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_SETSENDER') ?></span>
</span>
</td>
<td>
<?php echo VmHTML::checkbox('mail_from_setsender', $this->config->get('mail_from_setsender',0)); ?>
</td>
</tr>
<?php /* <tr>
<td class="key">
<span class="hasTip" title="<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_DATEFORMAT_EXPLAIN'); ?>">
3.) Add some code to the virtuemart class shopFunctionsF
=========================================================
FILE: components/com_virtuemart/helpers/shopfunctionsf.php (line 222)
Exchange the following function within the class:
/**
* With this function you can use a view to sent it by email.
* Just use a task in a controller todo the rendering of the email.
*
* @param string $view for example user, cart
* @param string $recipient shopper@whatever.com
* @param bool $vendor true for notifying vendor of user action (e.g. registration)
* @return true if successful
*/
private function sendVmMail (&$view, $recipient, $vendor=false ) {
$jlang =JFactory::getLanguage();
if(VmConfig::get('enableEnglish', 1)){
$jlang->load('com_virtuemart', JPATH_SITE, 'en-GB', true);
}
$jlang->load('com_virtuemart', JPATH_SITE, $jlang->getDefault(), true);
$jlang->load('com_virtuemart', JPATH_SITE, null, true);
ob_start();
$view->renderMailLayout($vendor, $recipient);
$body = ob_get_contents();
ob_end_clean();
$subject = (isset($view->subject)) ? $view->subject : JText::_('COM_VIRTUEMART_DEFAULT_MESSAGE_SUBJECT');
$mailer = JFactory::getMailer();
$mailer->addRecipient($recipient);
$mailer->setSubject($subject);
$mailer->isHTML(VmConfig::get('order_mail_html',true));
$mailer->setBody($body);
$mailfrom = array();
if($vendor){ //this is the mail to the vendor!
$mail_from_recipient = VmConfig::get('mail_from_recipient','0');
if ($mail_from_recipient =='1'){
if(isset($view->user)){
$mailfrom[0] = $view->user['email'];
$mailfrom[1] = $view->user['name'];
}else{
$user = JFactory::getUser(); //fallback
if (!empty($user->id)) {
$mailfrom[0] = $user->email;
$mailfrom[1] = $user->name;
}
}
} //else fetch the Joomla setup email address
}else{
$mailfrom[0]=$view->vendorEmail;
$mailfrom[1]= $view->vendor->vendor_name;
}
if(!empty($mailfrom)){
$mail_from_setSender = VmConfig::get('mail_from_setsender','0');
if ($mail_from_setSender=='0') {
$mailer->addReplyTo($mailfrom);
}else {
$mailer->setSender($mailfrom);
}
}
if (isset($view->mediaToSend)) {
foreach ((array)$view->mediaToSend as $media) {
//Todo test and such things.
$mailer->addAttachment($media);
}
}
return $mailer->Send();
}
I have tested this with the invoice mail on my live system for 24 hours;
Is there anybody who can test this new feature with Ask_Question or other mailing functions too?
p.s. FYI (@Milbo): The function sendVmMail is the latest from the cvs which I have merged with my code; but found a doubled line there:
$jlang =JFactory::getLanguage();
I removed this line.
cu Thomas Kuschel