0

我有一个 Ubuntu php7.0 服务器,我正在尝试使用我在这里找到的 php Mailparse 脚本

但是我确认 composer 安装在服务器上并且 mailparse 也在服务器上。但是,下面的脚本返回 500 错误,我将其跟踪到导致它的前两行代码,但不知道如何解决它。

所以我的意思是当我注释掉两行说

   require_once __DIR__.'/vendor/autoload.php';
   $Parser = new PhpMimeMailParser\Parser();

然后脚本将加载,但邮件解析当然不起作用?

 //load the php mime parse library
   require_once __DIR__.'/vendor/autoload.php';

   $Parser = new PhpMimeMailParser\Parser();

//Include the AWS SDK using the Composer autoloader.
require 'awssdk/aws-autoloader.php';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
// AWS Info
$bucketName = 'pipedemail';
$IAM_KEY = '******';
$IAM_SECRET = '******';
// Connect to AWS
try {
    // You may need to change the region. It will say in the URL when the bucket is open
    // and on creation. us-east-2 is Ohio, us-east-1 is North Virgina
    $s3 = S3Client::factory(
        array(
            'credentials' => array(
                'key' => $IAM_KEY,
                'secret' => $IAM_SECRET
            ),
            'version' => 'latest',
            'region'  => 'us-east-1'
        )
    );
} catch (Exception $e) {
    // We use a die, so if this fails. It stops here. Typically this is a REST call so this would
    // return a json object.
    die("Error: " . $e->getMessage());
}

// Use the high-level iterators (returns ALL of your objects).
$objects = $s3->getIterator('ListObjects', array('Bucket' => $bucketName));

foreach ($objects as $object) 
{
    $objectkey = $object['Key'];
    $path = "https://s3.amazonaws.com/pipedemail/$objectkey";

    //lets get the raw email file to parse it
    $Parser->setText(file_get_contents($path));

    // Once we've indicated where to find the mail, we can parse out the data
    $to = $Parser->getHeader('to');             // "test" <test@example.com>, "test2" <test2@example.com>
    $addressesTo = $Parser->getAddresses('to'); //Return an array : [[test, test@example.com, false],[test2, test2@example.com, false]]

    $from = $Parser->getHeader('from');             // "test" <test@example.com>
    $addressesFrom = $Parser->getAddresses('from'); //Return an array : test, test@example.com, false

    $subject = $Parser->getHeader('subject');

}
4

0 回答 0