dongqu5650 2019-04-25 02:28
浏览 79

为什么管道电子邮件到laravel命令不起作用?

I'm trying to pipe email in Cpanel to Laravel 5.8 command but something is wrong:

first of all I used this code to find the executable path of php:

echo exec('which php'); // returns "/usr/local/bin/php"

and I added the forwarder in cpanel to:

/usr/local/bin/php -q /home/abcd10/public_html/laravelapp/artisan emailparse 

the laravel artisan command:

<?php

namespace App\Console\Commands;

use Illuminate\Support\Facades\Storage;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Carbon;

class EmailParserCommand extends Command
{

    protected $signature = 'emailparse';

    protected $description = 'Parse an incomming email.';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {

        \DB::transaction(function () {  



            //$path = 'C:\Users\medoa\Desktop\email.eml'; // I used this to test the code in the localhost and it works manually
            $parser = new \PhpMimeMailParser\Parser();

            // Specify a stream to work with mail server (stream)
            $parser->setStream(fopen("php://stdin", "r"));

            $rawHeaderTo = $parser->getHeader('to');
            $rawHeaderFrom = $parser->getHeader('from');
            $arrayHeaderFrom = $parser->getAddresses('from');

            $subject = $parser->getHeader('subject');
            $body = $parser->getMessageBody('text');

            $upload = new \App\upload;
            $upload->from = $arrayHeaderFrom[0]['address'];
            $upload->subject = $subject;
            $upload->body = $body;
            $upload->save();

            $attachments = $parser->getAttachments();

            foreach ($attachments as $attachment)
             {
             $newfilename = Carbon\Carbon::now()->format('dmY') . Str::random(25) . $fileext;
      Storage::disk('public')->put('uploads/'.$newfilename, $attachment->getContent());

                $attobj = new \App\attachement;
                $attobj->filename = $newfilename;
                $attobj->original_filename = $attachment->getFilename();
                $attobj->upload_id = $upload->id;
                $attobj->size = Storage::disk('public')->size('uploads/'.$newfilename);
                $attobj->type = str_replace('.','',$fileext) ;

                $attobj->save();
            }
        });
    }   
}

I tested the code manually on the local host using this command "php artisan emailparse" using a locally stored file path and it works but I'm not sure whats wrong with what I did on the cpanel hosting.

the sender always recieve the follwing reply and nothing happens on the database:

This message was created automatically by mail delivery software. A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: pipe to |/home/itrade10/public_html/metastockdata/artisan emailparse generated by upload@metastockdata.itradegame.com local delivery failed

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题