veciak11 Posted January 2, 2015 Share Posted January 2, 2015 (edited) Witam, Po walce z tym, aby moja presta wysyłała maile (hosting na home.pl niestety) Mam błąd 500 po potwierdzeniu zamówienia: Parse error: syntax error, unexpected T_CATCH in /classes/Mail.php on line 311 ten odcinek kodu wygląda w ten sposób: // Multiple attachments? if (!is_array(current($file_attachment))) $file_attachment = array($file_attachment); foreach ($file_attachment as $attachment) if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) $message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime'])); /* Attach a file to order confirmation mail */ if ($template == 'pl/order_conf') { $file = _PS_ROOT_DIR_ . '/pliki/regulamin.pdf'; $message->attach(new Swift_Message_Attachment(file_get_contents($file), 'Regulamin', 'application/pdf')); } /* Send mail */ $send = $swift->send($message, $to, new Swift_Address($from, $from_name)); $swift->disconnect(); ShopUrl::resetMainDomainCache(); return $send; } catch (Swift_Exception $e) { return false; } } public static function sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption) { $swift = null; $result = false; try { if ($smtpChecked) { $smtp = new Swift_Connection_SMTP($smtpServer, $smtpPort, ($smtpEncryption == 'off') ? Swift_Connection_SMTP::ENC_OFF : (($smtpEncryption == 'tls') ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL)); $smtp->setUsername($smtpLogin); $smtp->setpassword($smtpPassword); $smtp->setTimeout(5); $swift = new Swift($smtp, Configuration::get('PS_MAIL_DOMAIN')); Pojawia się to także gdy próbuję wysłać maila poprzez formularz kontaktowy, wtedy otrzymuję błąd 500 z taką samą informacją jak wcześniej. Dodam, że nie usuwałem statusów zamówienia. Czy najdzie się ktoś miły (i trzeźwy ) i pomoże rozwiązać ten problem? Dodam jeszcze odnośnik do sklepu: http://krasnal.sklep.pl/ Edited January 2, 2015 by veciak11 (see edit history) Link to comment Share on other sites More sharing options...
0 endriu107 Posted January 2, 2015 Share Posted January 2, 2015 A co masz konkretnie w tej linii? Wrzuciłeś kod w opcji bez numeracji więc ciężko porównać go z oryginalnym plikiem, może coś wcześniej brakuje, albo w override masz ten plik nadpisany? Link to comment Share on other sites More sharing options...
0 veciak11 Posted January 2, 2015 Author Share Posted January 2, 2015 linijka 311: catch (Swift_Exception $e) { Link to comment Share on other sites More sharing options...
0 endriu107 Posted January 2, 2015 Share Posted January 2, 2015 A masz w okolicy 170 linii "try"? Plik nie jest nadpisywany w override? Link to comment Share on other sites More sharing options...
0 vekia Posted January 2, 2015 Share Posted January 2, 2015 no trochę w niefortunnym miejscu ten catch brakuje gdzieś z przodu try {} jak nie ma try{} to nie ma co złapać ;-) Link to comment Share on other sites More sharing options...
0 vekia Posted January 2, 2015 Share Posted January 2, 2015 tak to powinno wyglądać: try { /* Connect with the appropriate configuration */ if ($configuration['PS_MAIL_METHOD'] == 2) { if (empty($configuration['PS_MAIL_SERVER']) || empty($configuration['PS_MAIL_SMTP_PORT'])) { Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die); return false; } $connection = new Swift_Connection_SMTP( $configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == 'ssl' ? Swift_Connection_SMTP::ENC_SSL : (($configuration['PS_MAIL_SMTP_ENCRYPTION'] == 'tls' ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF)) ); $connection->setTimeout(4); if (!$connection) return false; if (!empty($configuration['PS_MAIL_USER'])) $connection->setUsername($configuration['PS_MAIL_USER']); if (!empty($configuration['PS_MAIL_PASSWD'])) $connection->setPassword($configuration['PS_MAIL_PASSWD']); } else $connection = new Swift_Connection_NativeMail(); if (!$connection) return false; $swift = new Swift($connection, Configuration::get('PS_MAIL_DOMAIN', null, null, $id_shop)); /* Get templates content */ $iso = Language::getIsoById((int)$id_lang); if (!$iso) { Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die); return false; } $iso_template = $iso.'/'.$template; $module_name = false; $override_mail = false; // get templatePath if (preg_match('#'.__PS_BASE_URI__.'modules/#', str_replace(DIRECTORY_SEPARATOR, '/', $template_path)) && preg_match('#modules/([a-z0-9_-]+)/#ui', str_replace(DIRECTORY_SEPARATOR, '/',$template_path), $res)) $module_name = $res[1]; if ($module_name !== false && (file_exists($theme_path.'modules/'.$module_name.'/mails/'.$iso_template.'.txt') || file_exists($theme_path.'modules/'.$module_name.'/mails/'.$iso_template.'.html'))) $template_path = $theme_path.'modules/'.$module_name.'/mails/'; elseif (file_exists($theme_path.'mails/'.$iso_template.'.txt') || file_exists($theme_path.'mails/'.$iso_template.'.html')) { $template_path = $theme_path.'mails/'; $override_mail = true; } if (!file_exists($template_path.$iso_template.'.txt') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT)) { Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:').' '.$template_path.$iso_template.'.txt', $die); return false; } elseif (!file_exists($template_path.$iso_template.'.html') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML)) { Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:').' '.$template_path.$iso_template.'.html', $die); return false; } $template_html = file_get_contents($template_path.$iso_template.'.html'); $template_txt = strip_tags(html_entity_decode(file_get_contents($template_path.$iso_template.'.txt'), null, 'utf-8')); if ($override_mail && file_exists($template_path.$iso.'/lang.php')) include_once($template_path.$iso.'/lang.php'); else if ($module_name && file_exists($theme_path.'mails/'.$iso.'/lang.php')) include_once($theme_path.'mails/'.$iso.'/lang.php'); else if (file_exists(_PS_MAIL_DIR_.$iso.'/lang.php')) include_once(_PS_MAIL_DIR_.$iso.'/lang.php'); else { Tools::dieOrLog(Tools::displayError('Error - The language file is missing for:').' '.$iso, $die); return false; } /* Create mail and attach differents parts */ $subject = '['.Configuration::get('PS_SHOP_NAME', null, null, $id_shop).'] '.$subject; $message = new Swift_Message($subject); $message->setCharset('utf-8'); /* Set Message-ID - getmypid() is blocked on some hosting */ $message->setId(Mail::generateId()); $message->headers->setEncoding('Q'); $template_vars = array_map(array('Tools', 'htmlentitiesDecodeUTF8'), $template_vars); $template_vars = array_map(array('Tools', 'stripslashes'), $template_vars); if (Configuration::get('PS_LOGO_MAIL') !== false && file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO_MAIL', null, null, $id_shop))) $logo = _PS_IMG_DIR_.Configuration::get('PS_LOGO_MAIL', null, null, $id_shop); else { if (file_exists(_PS_IMG_DIR_.Configuration::get('PS_LOGO', null, null, $id_shop))) $logo = _PS_IMG_DIR_.Configuration::get('PS_LOGO', null, null, $id_shop); else $template_vars['{shop_logo}'] = ''; } ShopUrl::cacheMainDomainForShop((int)$id_shop); /* don't attach the logo as */ if (isset($logo)) $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_EmbeddedFile(new Swift_File($logo), null, ImageManager::getMimeTypeByExtension($logo))); if ((Context::getContext()->link instanceof Link) === false) Context::getContext()->link = new Link(); $template_vars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME', null, null, $id_shop)); $template_vars['{shop_url}'] = Context::getContext()->link->getPageLink('index', true, Context::getContext()->language->id, null, false, $id_shop); $template_vars['{my_account_url}'] = Context::getContext()->link->getPageLink('my-account', true, Context::getContext()->language->id, null, false, $id_shop); $template_vars['{guest_tracking_url}'] = Context::getContext()->link->getPageLink('guest-tracking', true, Context::getContext()->language->id, null, false, $id_shop); $template_vars['{history_url}'] = Context::getContext()->link->getPageLink('history', true, Context::getContext()->language->id, null, false, $id_shop); $template_vars['{color}'] = Tools::safeOutput(Configuration::get('PS_MAIL_COLOR', null, null, $id_shop)); $swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $template_vars)), 'decorator'); if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT) $message->attach(new Swift_Message_Part($template_txt, 'text/plain', '8bit', 'utf-8')); if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML) $message->attach(new Swift_Message_Part($template_html, 'text/html', '8bit', 'utf-8')); if ($file_attachment && !empty($file_attachment)) { // Multiple attachments? if (!is_array(current($file_attachment))) $file_attachment = array($file_attachment); foreach ($file_attachment as $attachment) if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) $message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime'])); } /* Send mail */ $send = $swift->send($message, $to_list, new Swift_Address($from, $from_name)); $swift->disconnect(); ShopUrl::resetMainDomainCache(); if ($send && Configuration::get('PS_LOG_EMAILS')) { $mail = new Mail(); $mail->template = substr($template, 0, 62); $mail->subject = substr($subject, 0, 254); $mail->id_lang = (int)$id_lang; foreach (array_merge($to_list->getTo(), $to_list->getCc(), $to_list->getBcc()) as $recipient) { $mail->id = null; $mail->recipient = substr($recipient->getAddress(), 0, 126); $mail->add(); } } return $send; } catch (Swift_Exception $e) { return false; } ten końcowy fragment catch() odnosi się do poprzedzającego ogromnego fragmentu try{ } Link to comment Share on other sites More sharing options...
0 veciak11 Posted January 7, 2015 Author Share Posted January 7, 2015 @vekiaNiestety kod, który mi podałeś nie zgadza się do końca. Ja w swoim dodałem wyłącznie kilka linijek, aby automatycznie dodawać załącznik do pierwszego e-maila zaraz po dokonaniu zakupu (potwierdzeniu w ostatnim kroku) według instrukcji @Matsu z tego tematu: http://www.prestashop.com/forums/topic/391101-za%C5%82%C4%85cznik-pdf-do-pierwszej-wiadomo%C5%9Bci-dla-kupuj%C4%85cego-presta-16/ - jak robiłem to za pierwszym razem to działało znakomicie, niestety podczas przenoszenia sklepu nadpisałem plik index i musiałem przeinstalować sklep.Kod który podałeś jest identyczny do momentu (wstawiam cześć TWOJEGO kodu, który jest inny niż mój a którego nie modyfikowałem: if ($send && Configuration::get('PS_LOG_EMAILS')) { $mail = new Mail(); $mail->template = substr($template, 0, 62); $mail->subject = substr($subject, 0, 254); $mail->id_lang = (int)$id_lang; foreach (array_merge($to_list->getTo(), $to_list->getCc(), $to_list->getBcc()) as $recipient) { $mail->id = null; $mail->recipient = substr($recipient->getAddress(), 0, 126); $mail->add(); } } return $send; } catch (Swift_Exception $e) { return false; } A u mnie wygląda to tak: return $send; } catch (Swift_Exception $e) { return false; } } public static function sendMailTest($smtpChecked, $smtpServer, $content, $subject, $type, $to, $from, $smtpLogin, $smtpPassword, $smtpPort = 25, $smtpEncryption) { $swift = null; $result = false; try { if ($smtpChecked) { $smtp = new Swift_Connection_SMTP($smtpServer, $smtpPort, ($smtpEncryption == 'off') ? Swift_Connection_SMTP::ENC_OFF : (($smtpEncryption == 'tls') ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_SSL)); $smtp->setUsername($smtpLogin); $smtp->setpassword($smtpPassword); $smtp->setTimeout(5); $swift = new Swift($smtp, Configuration::get('PS_MAIL_DOMAIN')); } else $swift = new Swift(new Swift_Connection_NativeMail(), Configuration::get('PS_MAIL_DOMAIN')); $message = new Swift_Message($subject, $content, $type); if ($swift->send($message, $to, $from)) $result = true; $swift->disconnect(); } catch (Swift_ConnectionException $e) { $result = $e->getMessage(); } catch (Swift_Message_MimeException $e) { $result = $e->getMessage(); } return $result; } Posiadam prestę 1.6.0.9 pobraną z prestashop.com (z głównej strony).Jeżeli Twój kod jest poprawny to proszę powiedz w którym (od - do) miejscu mam zmienić swój kod na Twój. Dziękuje za Pomoc chłopaki Link to comment Share on other sites More sharing options...
0 tomakus Posted August 19, 2019 Share Posted August 19, 2019 Ponawiam wątek, ten sam problem. W załączniku screen z błędami bardzo proszę o pomoc. Link to comment Share on other sites More sharing options...
Question
veciak11
Witam,
Po walce z tym, aby moja presta wysyłała maile (hosting na home.pl niestety) Mam błąd 500 po potwierdzeniu zamówienia:
ten odcinek kodu wygląda w ten sposób:
Pojawia się to także gdy próbuję wysłać maila poprzez formularz kontaktowy, wtedy otrzymuję błąd 500 z taką samą informacją jak wcześniej.
Dodam, że nie usuwałem statusów zamówienia.
Czy najdzie się ktoś miły (i trzeźwy ) i pomoże rozwiązać ten problem?
Edited by veciak11 (see edit history)Dodam jeszcze odnośnik do sklepu: http://krasnal.sklep.pl/
Link to comment
Share on other sites
7 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now