Jump to content
  • 0
veciak11

błąd 500 w ostatnim kroku składania zamówienia

Question

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 by veciak11 (see edit history)

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

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?

Share this post


Link to post
Share on other sites
  • 0

no trochę w niefortunnym miejscu ten catch

 

brakuje gdzieś z przodu try {}

 

jak nie ma try{} to nie ma co złapać ;-) 

Share this post


Link to post
Share on other sites
  • 0

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{ }

Share this post


Link to post
Share on other sites
  • 0

@vekia

Niestety 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 :)

 

Share this post


Link to post
Share on other sites
  • 0

Ponawiam wątek, ten sam problem.
W załączniku screen z błędami bardzo proszę o pomoc.

Ashampoo_Snap_poniedziałek, 19 sierpnia 2019_02h49m06s_001_.png

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More