Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change msgHtml to allow callback as image resolver #1799

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

conrallendale
Copy link

Change the second parameter of the function msgHtml to accept a callable, beside the current string parameter. This way, I can implement my own way of getting the image data. In my case, using S3, I can request S3 for a object and return the image data, name and type. Eg:

$mail->msgHTML('<img src="my-image.jpg" />', function($url) use ($s3client) {
    $object = $s3client->getObject([ "Bucket" => "my-bucket", "Key" => $url ]);

    return [
        "name" => $url,
        "data" => (string) $object["Body"],
        "type" => $object["@metadata"]["headers"]["content-type"]
    ];
});

@Synchro
Copy link
Member

Synchro commented Sep 25, 2019

This all looks quite reasonable - could you add a test to cover this change please?

$directory .= '/';
$added = false;

// Only process relative URLs if a basedir is provided (i.e. no absolute local paths)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the var name in the comment :)

static::ENCODING_BASE64,
static::_mime_types((string) static::mb_pathinfo($filename, PATHINFO_EXTENSION))
);
} elseif (is_callable($imageResolver)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the passed param is not callable we can thrown an exception telling about it. Otherwise it will be hard to debug what exactly is happening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants