News:

Support the VirtueMart project and become a member

Main Menu

Error when sending "Recommend to a friend" email

Started by Ghost, September 03, 2024, 10:43:27 AM

Previous topic - Next topic

Ghost

When sending recommend to a friend email as guest, an error occurs:
Error Message: Invalid address:  (Reply-To):
In file "JROOT/libraries/vendor/phpmailer/phpmailer/src/PHPMailer.php" on line 1094
#0 JROOT/libraries/vendor/phpmailer/phpmailer/src/PHPMailer.php(1059): PHPMailer\PHPMailer\PHPMailer->addOrEnqueueAnAddress()
#1 JROOT/libraries/src/Mail/Mail.php(292): PHPMailer\PHPMailer\PHPMailer->addReplyTo()
#2 JROOT/libraries/src/Mail/Mail.php(483): Joomla\CMS\Mail\Mail->add()
#3 JROOT/components/com_virtuemart/helpers/shopfunctionsf.php(916): Joomla\CMS\Mail\Mail->addReplyTo()
#4 JROOT/components/com_virtuemart/helpers/shopfunctionsf.php(768): shopFunctionsF::sendVmMail()
#5 JROOT/components/com_virtuemart/controllers/productdetails.php(199): shopFunctionsF::renderMail()
#6 JROOT/libraries/src/MVC/Controller/BaseController.php(693): VirtueMartControllerProductdetails->mailRecommend()
#7 JROOT/components/com_virtuemart/virtuemart.php(133): Joomla\CMS\MVC\Controller\BaseController->execute()
#8 JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php(71): require_once('...')
#9 JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php(73): Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher\{closure}()
#10 JROOT/libraries/src/Component/ComponentHelper.php(361): Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch()
#11 JROOT/libraries/src/Application/SiteApplication.php(208): Joomla\CMS\Component\ComponentHelper::renderComponent()
#12 JROOT/libraries/src/Application/SiteApplication.php(249): Joomla\CMS\Application\SiteApplication->dispatch()
#13 JROOT/libraries/src/Application/CMSApplication.php(293): Joomla\CMS\Application\SiteApplication->doExecute()
#14 JROOT/includes/app.php(61): Joomla\CMS\Application\CMSApplication->execute()
#15 JROOT/index.php(32): require_once('...')
#16 {main}

Possible solution: the value of $replyTo[0] should be checked before calling $mailer->addReplyTo() https://dev.virtuemart.net/projects/virtuemart/repository/virtuemart/entry/trunk/virtuemart/components/com_virtuemart/helpers/shopfunctionsf.php?utf8=%E2%9C%93&rev=11050#L915

Also $replyTo could be converted to string to simplify code:
$replyTo = '';
$replyToName = '';

if(!$noVendorMail) {
$replyTo = $view->vendorEmail;
$replyToName = $view->vendor->vendor_name;
} else {
if(isset($view->orderDetails['details']) && isset($view->orderDetails['details']['BT'])) {
$replyTo = $view->orderDetails['details']['BT']->email;
$replyToName = $view->orderDetails['details']['BT']->first_name . ' ' . $view->orderDetails['details']['BT']->last_name;
} else {
if(is_object($view->user)){
$replyTo = isset($view->user->email)? $view->user->email:'';
$replyToName = isset($view->user->name)? $view->user->name:'';
} else {
$replyTo = isset($view->user['email'])? $view->user['email']:'';
$replyToName = isset($view->user['name'])? $view->user['name']:'';
}
}
}

if($replyTo) {
if(version_compare(JVERSION, '3.5', 'ge')) {
$mailer->addReplyTo($replyTo, $replyToName);
} else {
$mailer->addReplyTo([$replyTo, $replyToName]);
}
}

VM 4.2.18.11050