Hey alle zusammen,
ich arbeite gerade an einem Plugin, welches mir die Dokumente einer Bestellung per Email rausschicken kann. Nun geht keinerlei Email raus, aber ich hab leider auch keine Ahnung wie ich dem Problem so wirklich auf den Grund gehen kann.
Was mach ich bisher?
public function sendDocumentsAction()
{
$orderIds = json_decode($this->Request()->get('orderIds'));
if ($orderIds && count($orderIds) == 0)
{
return $this->View()->assign([
'success' => false,
]);
}
$config = array('auth' => 'login',
'username' => '',
'password' => '',
'port' => '465',
'ssl' => 'ssl');
$transport = new Zend_Mail_Transport_Smtp('', $config);
// Zend_Mail::setDefaultTransport($transport);
/**
* @var \Enlight_Components_Mail $mail
*/
// Create a mail instance
$mail = Shopware()->Mail();
$mail->setBodyText('Blafasel');
$mail->setFrom('bla@fasel.de', 'Blafasel');
$mail->addTo('bla@fasel.de', 'Blafasel');
$subject = "Blafasel for: ";
// cycle through all orders
foreach ($orderIds as $orderId)
{
// create the document SQL
$repository = $this->getRepository('Shopware\\Models\\Order\\Document\\Document');
$builder = $repository->createQueryBuilder('document');
$builder->select()
->where('document.orderId = :orderId AND (document.type = 1 OR document.type = 4)')
->setParameter('orderId', $orderId); // Order id
// Get all documents for this order
/**
* @var \Shopware\Models\Order\Document\Document[] $documents
*/
$documents = $builder->getQuery()->getResult();
if (!$documents) continue;
// Get order number and add to subject
$order = $documents[0]->getOrder();
if ($order)
{
$subject = $subject . " " . $order->getNumber() . "";
}
// cycle through all documents
foreach ($documents as $document)
{
/**
* @var \Shopware\Models\Order\Document\Document $document
*/
$hash = $document->getHash();
if ($hash)
{
$pdfPath = Shopware()->DocPath() . 'files/documents/' . $hash . '.pdf';
$pdfContent = file_get_contents($pdfPath);
if (false !== $pdfContent)
{
$attachment = new Zend_Mime_Part($pdfContent);
$attachment->type = 'application/pdf';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename = ($order? $order->getNumber() . ($document->getTypeId() == 1 ? '_Rechnung' : '_Stornorechnung') . '.pdf' : $hash . '.pdf'); // name of file
$mail->addAttachment($attachment);
}
else
{
$this->logError("The document with the ID " . $document->getId() . " could not be found.");
}
}
}
}
$mail->setSubject($subject);
try
{
$mail->send($transport);
}
catch (Exception $e)
{
$this->logError('Could not send email '.$e);
}
}
Soweit so gut. Durchlaufen tut es, aber leider ohne Erfolg. Kann mir da vielleicht jemand helfen?