Grüß euch,
um Mails via PHP aufzurufen und in der DB zu speichern, habe ich auf folgende Klasse zurück gegriffen und in Laravel eingefügt
Soweit klappt auch alles. Lediglich die Mail Anhänge werden im Ordner app/Http/Controllers als .bin File zwischengespeichert was natürlich nicht sein soll.
Optimal wäre im Ordner public bzw. das diese am Ende gelöscht werden oder alternativ erst gar nicht angelegt.
Ich habe schon so einiges versucht, hänge aber fest.
app/Http/Controllers/MailController
Mailbox.php (aus der Klasse)
Evtl. könnt Ihr auch dies mal helfen.
um Mails via PHP aufzurufen und in der DB zu speichern, habe ich auf folgende Klasse zurück gegriffen und in Laravel eingefügt
GitHub - barbushin/php-imap: Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP) - barbushin/php-imap
github.com
Soweit klappt auch alles. Lediglich die Mail Anhänge werden im Ordner app/Http/Controllers als .bin File zwischengespeichert was natürlich nicht sein soll.
Optimal wäre im Ordner public bzw. das diese am Ende gelöscht werden oder alternativ erst gar nicht angelegt.
Ich habe schon so einiges versucht, hänge aber fest.
app/Http/Controllers/MailController
PHP:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Mail;
use Illuminate\Mail\Mailer;
use Illuminate\Support\Facades\Auth;
use PhpImap\Exceptions\ConnectionException;
use PhpImap\Mailbox;
use Illuminate\Support\Facades\DB;
use function GuzzleHttp\Promise\all;
class MailController extends Controller
{
public function checking()
{
.......
// Save attachments one by one
if (!$mailbox->getAttachmentsIgnore()) {
$attachments = $email->getAttachments();
foreach ($attachments as $attachment) {
// Set individually filePath for each single attachment
// In this case, every file will get the current Unix timestamp
$attachment->setFilePath('files/' . $attachment->name);
$attachment->saveToDisk();
// Anhänge speichern
DB::table('mails_attachements')->insert(
['name' => $attachment->name, 'mail_id' => $mail->id]
);
echo $attachment->sizeInBytes.'<br>';
}
}
// Mail auf dem Server als gelesen markieren
$mailbox->markMailAsRead($mail_id);
}
$mailbox->disconnect();
}
}
Mailbox.php (aus der Klasse)
PHP:
$attachmentsDir = $this->getAttachmentsDir();
if (null != $attachmentsDir) {
$fileSysName = \bin2hex(\random_bytes(16)).'.bin';
$filePath = $attachmentsDir.DIRECTORY_SEPARATOR.$fileSysName;
if (\strlen($filePath) > self::MAX_LENGTH_FILEPATH) {
$ext = \pathinfo($filePath, PATHINFO_EXTENSION);
$filePath = \substr($filePath, 0, self::MAX_LENGTH_FILEPATH - 1 - \strlen($ext)).'.'.$ext;
}
$attachment->setFilePath($filePath);
$attachment->saveToDisk();
}
Evtl. könnt Ihr auch dies mal helfen.
Zuletzt bearbeitet: