---
title: "Update auf 4.5 / t3lib und Mailversand"
url: "https://www.typo3.net/d/111016-update-auf-45-t3lib-und-mailversand"
source: "typo3.net"
tags: ["Allgemein","E-Mail-Versand","Frage","Update & Upgrade"]
created: "2012-06-18"
last_reply: "2012-06-18"
replies: 2
solved: false
page: 1
pages: 1
lang: "de"
---

# Update auf 4.5 / t3lib und Mailversand

Allgemein · 2 Antworten · gestartet 2012-06-18

## Eröffnungsbeitrag

**pixelparts** · 2012-06-18 · [Beitrag #1](https://www.typo3.net/d/111016-update-auf-45-t3lib-und-mailversand/1)

Hallo

Nach dem Update versenden einige Erweiterungen keine Mail mehr. Leider werden diese Ext. nicht mehr gepflegt, also muss ich das machen. Dazu benötige ich Eure Hilfe. Was muss ich ändern, um den Mailversand wieder zum Laufen zu bringen? Über ein paar Tipps würde ich mich wirklich freuen.

Hier ein Script, welches Mails (nicht mehr) versendet ...

```php
require_once(PATH_t3lib . 'class.t3lib_htmlmail.php');

class autoMail {
	/**
	 * local configuration
	 *
	 * @var array $this->conf
	 */
	protected $conf = array();

	/**
	 * Path of where to store the orders
	 *
	 * @var string
	 */
	protected $uploadPath = 'uploads/tx_mcfbwkatalog/';

	/**
	 * @var array
	 */
	protected $defaultEmailData = array(
		'subject' => 'Sammelkatalogbestellung',
		'from' => 'info@domain.de',
		'fromName' => 'domain.de',
		'reply' => 'info@domain.de',
		'text' => 'Im Anhang finden Sie die aktuellen Katalogbestellungen von domain.de',
		'to' => ''
	);

	/**
	 * @var array
	 */
	protected $multipleFiles = array();


	/**
	 * Main function calls subfunctions
	 * sendNewsletterTo() and
	 * sendKatalogBuendel()
	 *
	 */
	public function main() {
		//load configuration-values from the typo3 backend
		$this->conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['bw_katalog']);

		$this->sendNewsletterTo();
		$this->sendKatalogBuendel();
	}

	/**
	 * copy newsletter_anmeldungen.csv to an archive and send an email
	 * with the attached file
	 */
	protected function sendNewsletterTo() {
		$sourceFilename = PATH_site . $this->uploadPath . 'newsletter_anmeldungen.csv';

		if (file_exists($sourceFilename)) {
			$archiveFilename = sprintf(
				PATH_site . $this->uploadPath  . 'newsletter_anmelde_archive/%s-%s-%s.csv',
				date('Y'), date('m'), date('d')
			);
			rename($sourceFilename, $archiveFilename);

			$mailData = array(
				'subject' => 'newsletter csv',
				'from' => 'info@domain.de',
				'fromName' => 'domain.de',
				'reply' => 'info@domain.de',
				'text' => 'Hallo liebes Team

Im Anhang finden Sie eine CSV Datei mit allen neuen Newsletteranmeldungen von diesem Monat die über die Katalogbestellung kommt.',
				'receiver' => 'info@domain.de'
			);
			$this->sendMail($mailData, $archiveFilename, FALSE);
		}
	}

	/**
	 * copy katalog_nnn.csv-files to archive directory and send an email
	 * with this attached file
	 */
	protected function sendKatalogBuendel() {
		$fp = opendir(PATH_site . $this->uploadPath . 'buendelcvs/');
		if ($fp) {
			while ($filename = readdir($fp)) {
				if (preg_match('@^katalog_(?P<uid>\d+)(_(?P<country>[a-z]+))?\.csv$@i', $filename, $result) && is_numeric($result['uid'])) {
					$uid = $result['uid'];
					$country = $result['country'] ? '_' . $result['country'] : '';

					$data = current($GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid, email AS receiver', 'tx_mcfbwkatalog_data', 'uid =' . $uid));

					$sourceFilename = sprintf(PATH_site . $this->uploadPath  . 'buendelcvs/%s', $filename);
					$archiveFilename = sprintf(PATH_site . $this->uploadPath  . 'buendelcvs/archive/katalog_%s%s_%s.csv', $uid, $country, date('Y-m-d'));

					if ($uid == 7) {
						$this->addToMultipleFiles($data, $sourceFilename, $archiveFilename);
					} else {
						$this->sendSingleFile($data, $sourceFilename, $archiveFilename);
					}
				}
			}

			if ($this->hasMultipleFiles()) {
				$this->sendMultipleFiles();
			}
		}
		closedir($fp);
	}


	/**
	 * @param array $data
	 * @param string $sourceFilename
	 * @param string $archiveFilename
	 * @return void
	 */
	protected function sendSingleFile($data, $sourceFilename, $archiveFilename) {
		rename($sourceFilename, $archiveFilename);
		$mailData = array_merge($this->defaultEmailData, $data);
		$this->sendMail($mailData, $archiveFilename, TRUE);
	}

	/**
	 * @param array $data
	 * @param string $sourceFilename
	 * @param string $archiveFilename
	 * @return void
	 */
	protected function addToMultipleFiles($data, $sourceFilename, $archiveFilename) {
		if (!isset($this->multipleFiles[$data['uid']])) {
			$this->multipleFiles[$data['uid']] = array(
				'data' => $data,
				'files' => array(),
			);
		}

		$this->multipleFiles[$data['uid']]['files'][$sourceFilename] = $archiveFilename;
	}

	/**
	 * @return boolean
	 */
	protected function hasMultipleFiles() {
		return count($this->multipleFiles) ? TRUE : FALSE;
	}

	/**
	 * @return void
	 */
	protected function sendMultipleFiles() {
		foreach ($this->multipleFiles as $uid => $dataAndFiles) {
			$mailData = array_merge($this->defaultEmailData, $dataAndFiles['data']);
			$files = array();
			foreach ($dataAndFiles['files'] as $sourceFilename => $archiveFilename) {
				rename($sourceFilename, $archiveFilename);
				$files[] = $archiveFilename;
			}
			$this->sendMail($mailData, $files, TRUE);
		}
	}


	/**
	 * Send an email with an attachment
	 *
	 * @param array $mailData
	 * @param string|array $attachment filename to attach
	 * @param boolean $addBCC whether to send to bcc address in addition or not
	 * @return void
	 */
	public function sendMail($mailData, $attachment, $addBCC = FALSE) {
		$mail = new t3lib_htmlmail;
		$mail->start();
		$mail->subject = $mailData['subject'];
		$mail->from_name = $mailData['fromName'];
		$mail->from_email = $mailData['from'];
		$mail->replyto_email = $mailData['reply'];
		$mail->replyto_name = $mailData['fromName'];
		$mail->priority = 3;
		$mail->theParts['html']['path'] = '';
		$mail->extractMediaLinks();
		$mail->extractHyperLinks();
		$mail->fetchHTMLMedia();
		$mail->substMediaNamesInHTML(0); // 0 = relative
		$mail->substHREFsInHTML();
		$mail->setHeaders();

		if ($addBCC) {
			$mail->add_header('BCC: ' . $this->conf['bcc_email']);
		}

		if (!is_array($attachment)) {
			$mail->addAttachment($attachment);
		} else {
			foreach ($attachment as $singleAttachment) {
				$mail->addAttachment($singleAttachment);
			}
		}

		$mail->theParts['plain']['content'] = $mailData['text'];
		$mail->addPlain($mail->theParts['plain']['content']);
		$mail->setContent();

		$mail->setRecipient($mailData['receiver']);

		$mail->sendTheMail();
	}
}

?>
```

Viele Grüße, Uwe

## Antworten

### [#2](https://www.typo3.net/d/111016-update-auf-45-t3lib-und-mailversand/2) · igorshmigor · 2012-06-18

Hast Du mal versucht, ob es funktioniert, wenn Du im Install-Tool
ein Häkchen für forceReturnPath setzt?

### [#3](https://www.typo3.net/d/111016-update-auf-45-t3lib-und-mailversand/3) · pixelparts · 2012-06-18

> **igorshmigor schrieb:**
>
> Hast Du mal versucht, ob es funktioniert, wenn Du im Install-Tool
> ein Häkchen für forceReturnPath setzt?

Danke für den Tipp. Ich hab das Häkchen bei [substituteOldMailAPI] = 0
rausgenommen. Aber ich werde mal nachlesen, was forceReturnPath macht. Ist das ev. die bessere Lösung?

Herzlichst, Uwe

---

Quelle: „Update auf 4.5 / t3lib und Mailversand“, typo3.net, https://www.typo3.net/d/111016-update-auf-45-t3lib-und-mailversand
Beiträge von Mitgliedern des Forums. Bitte mit Link auf die Diskussion zitieren.
