Laravel邮件发送错误$地址必须是公开的

3yhwsihp  于 2023-06-07  发布在  其他
关注(0)|答案(1)|浏览(155)

Laravel Framework 10.13.1我根据文档生成一个邮件文件及其标记

php artisan make:mail TokenVerification --markdown=emails.token

呼叫

Mail::to('admin@example.com')->send(new TokenVerification());

误差

{
    "message": "Access level to Symfony\\Component\\Mime\\Address::$address must be public (as in class Illuminate\\Mail\\Mailables\\Address)",
    "exception": "Symfony\\Component\\ErrorHandler\\Error\\FatalError",
    "file": "/var/www/ipala-udev/vendor/symfony/mime/Address.php",
    "line": 25,
    "trace": []
}

这是laravel生成TokenVerification.php的邮件代码

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class TokenVerification extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Token Verification',
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            markdown: 'emails.token',
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}

我认为问题出在Envelope对象中,它有地址字段,但不清楚如何修复它。有没有办法找出错误的来源?
错误和StackTrace

Access level to Symfony\Component\Mime\Address::$address must be public (as in class Illuminate\Mail\Mailables\Address)

namespace Symfony\Component\Mime;

use Egulias\EmailValidator\EmailValidator;

use Egulias\EmailValidator\Validation\MessageIDValidation;

use Egulias\EmailValidator\Validation\RFCValidation;

use Symfony\Component\Mime\Encoder\IdnAddressEncoder;

use Symfony\Component\Mime\Exception\InvalidArgumentException;

use Symfony\Component\Mime\Exception\LogicException;

use Symfony\Component\Mime\Exception\RfcComplianceException;

/**

 * @author Fabien Potencier <fabien@symfony.com>

 */

final class Address extends \Illuminate\Mail\Mailables\Address

{

    /**

     * A regex that matches a structure like 'Name <email@address.com>'.

     * It matches anything between the first < and last > as email address.

     * This allows to use a single string to construct an Address, which can be convenient to use in

     * config, and allows to have more readable config.

     * This does not try to cover all edge cases for address.

     */

    private const FROM_STRING_PATTERN = '~(?<displayName>[^<]*)<(?<addrSpec>.*)>[^>]*~';

    private static EmailValidator $validator;

    private static IdnAddressEncoder $encoder;

    private string $address;

打开文件`/vendor/symfony/mime/Address.php ide phpstorm立即告诉我什么要更改为public,错误正在更改

{
    "message": "Type of Symfony\\Component\\Mime\\Address::$address must not be defined (as in class Illuminate\\Mail\\Mailables\\Address)",
    "exception": "Symfony\\Component\\ErrorHandler\\Error\\FatalError",
    "file": "/var/www/ipala-udev/vendor/symfony/mime/Address.php",
    "line": 25,
    "trace": []
}
j0pj023g

j0pj023g1#

您不应该修改供应商文件,因为在没有正确锁定的情况下更新软件包或进行新安装时,其中的任何修改都将被覆盖。
我建议您删除vendor文件夹并运行composer install命令创建一个新文件夹。
请记住,这将删除您在供应商文件夹中所做的任何更改,但这将修复您的问题和许多隐藏的其他问题。

相关问题