为什么将电子邮件传送到laravel命令不起作用?

时间:2019-04-25 02:28:48

标签: php laravel pipe cpanel artisan

我正在尝试将Cpanel中的电子邮件通过管道发送到Laravel 5.8命令,但是出了点问题:

首先,我使用以下代码来查找php的可执行路径:

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

,然后我在cpanel中将转发器添加到:

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

laravel artisan命令:

<?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();
            }
        });
    }   
}

我使用本地存储的文件路径,使用“ php artisan emailparse”命令在本地主机上手动测试了代码,它可以工作,但是我不确定在cpanel托管上的操作出了什么问题。

发件人始终会收到以下答复,并且数据库上没有任何反应:

  

此消息是由邮件传递软件自动创建的。您发送的邮件无法传递到其一个或多个   收件人。这是一个永久性错误。以下地址失败:传送至| / home / itrade10 / public_html / metastockdata / artisan emailparse(由upload@metastockdata.itradegame.com生成的本地传递失败)

0 个答案:

没有答案