Проблема отправки встроенных изображений с помощью PHP PostmarkClient - PullRequest
0 голосов
/ 07 марта 2019

У меня есть существующее электронное письмо, которое отправляется пользователям, когда они забывают свой пароль. Я хочу добавить встроенные изображения в это письмо, чтобы показать людям, которые не очень разбираются в технологиях, где нажимать и т. Д.

Вот мой код:

$htmlBody = 'Here is a <span style="background-color: yellow;font-weight: bold;">one-time use</span> password.  If not used within 72 hours, it will expire and you will need to request another temporary password. ';
        $htmlBody .= '<br><br>Please follow the steps below carefully to reset your password.<br>';
        $htmlBody .= '<ol><li><strong>Log out of the template manager</strong> (right click on the template manager in the task bar and choose Exit from the menu).</li>';
        $htmlBody .= '<img src="data:image/png;base64,' . base64_encode('ZmlsZTovQzovd2FtcDY0L3d3dy90YWJ1bGEvaW1nL2V4aXRfZnJvbV90ZW1wbGF0ZV9tYW5hZ2VyLnBuZw==') . '" width="325" height="149">';
        $htmlBody .= '<li>Copy the password below and use it to sign in to your account on <a href="https://########/">####</a>.';
        $htmlBody .= '<ul><li style="list-style-type: none;padding-top:5px;padding-bottom:5px;">Password: <span style="background-color: yellow;">' . $newpassword . '</span>';
        $htmlBody .= '</li></ul></li>';
        $htmlBody .= '<li>Once you log in, you will be prompted to change your password.  A message will appear in red at the top of the ##### page if you changed your password successfully.</li>';
        $htmlBody .= '<li>Once you have changed your password, you will automatically be logged out and have to log in again with your new password.</li>';
        $htmlBody .= '<li>Update your password manager with your new password, if you use one.</li>';
        $htmlBody .= '<li>Log in to the template manager using your new password.</li>';
        $htmlBody .= '<li>If you use a separate password manager for the template manager, update your password there too.</li></ol>';
        $htmlBody .= '<br><br>Thank you,<br>eScribers';
        $email = [
            'tag'         => 'temporaryPasswordSent',
            'to'          => $transcriber->email,
            'from'        => '#####',
            'from_name'   => '####',
            'subject'     => 'Your temporary #### password',
            'html'        => $htmlBody
        ];
        $emailClient = new emailClient();
        $emailClient->sendEmail($email);

Письмо отправлено, но в письме появляется пустое поле, а не изображение. Я много раз пытался преобразовать изображение в base64, но это не помогает. Может кто-нибудь сказать мне, что я делаю не так? Спасибо.

РЕДАКТИРОВАТЬ: Кто-нибудь? Я действительно изо всех сил пытаюсь понять это. Я не думаю, что это разрешение, потому что я повторил изображения на странице входа, и они появились без проблем.

1 Ответ

0 голосов
/ 11 марта 2019

Сотрудник, наконец, понял это.Вот код, если он может помочь кому-то еще:

    $attachments = $this->setForgotPasswordAttachmentImages();
    $htmlBody = 'Here is a <span style="background-color: yellow;font-weight: bold;">one-time use</span> password.  If not used within 72 hours, it will expire and you will need to request another temporary password. ';
    $htmlBody .= '<br><br>Please follow the steps below carefully to reset your password.<br>';
    $htmlBody .= '<ol><li><strong>Log out of the template manager</strong> (right click on the template manager in the task bar and choose Exit from the menu).</li><br />';
    $htmlBody .= '<br /><img src="cid:exit_from_template_manager.png" width="325" height="149"><br />';
    $htmlBody .= '<li>Copy the password below and use it to sign in to your account on <a href="https://####/">###</a>.';
    $htmlBody .= '<ul><li style="list-style-type: none;padding-top:5px;padding-bottom:5px;">Password: <span style="background-color: yellow;">' . $newpassword . '</span>';
    $htmlBody .= '</li></ul></li>';
    $htmlBody .= '<br /><img src="cid:log_in_to_###.jpg" width="185" height="175"><br /><br />';
    $htmlBody .= '<li>Once you log in, you will be prompted to change your password.';
    $htmlBody .= 'A message will appear in red at the top of the ### page if you changed your password successfully.</li>';
    $htmlBody .= '<br /><img src= "cid:password_successfully_changed_message.png" width="190" height="309"><br /><br />';
    $htmlBody .= '<li>Once you have changed your password, you will automatically be logged out and have to log in again with your new password.</li>';
    $htmlBody .= '<li>Update your password manager with your new password, if you use one.</li>';
    $htmlBody .= '<li>Log in to the template manager using your new password.</li>';
    $htmlBody .= '<br /><img src="cid:login_to_template_manager.png" width="361" height="298"><br /><br />';
    $htmlBody .= '<li>If you use a separate password manager for the template manager, update your password there too.</li></ol>';
    $htmlBody .= '<br><br>Thank you,<br>eScribers';
    $data = [
        'From' => '####',
        'To' => $transcriberEmail,
        'Subject' => 'Your temporary #### password',
        'Tag' => 'temporaryPasswordSent',
        'HtmlBody' => $htmlBody,
        'Attachments' => $attachments
    ];
    $emailClient = new emailClient();
    return $emailClient->sendEmailWithInlineAttachments($data);

И:

public function setForgotPasswordAttachmentImages()
{
    $attachment = [];
    $attachment[] = PostmarkAttachment::fromFile(FCPATH . 'img\exit_from_template_manager.png', 'exit_from_template_manager.png', 'image/jpg',
        'cid:exit_from_template_manager.png');

    $attachment[] = PostmarkAttachment::fromFile(FCPATH . 'img\log_in_to_###.jpg', 'log_in_to_###.jpg',
        'image/png', 'cid:log_in_to_###.jpg');

    $attachment[] = PostmarkAttachment::fromFile(FCPATH . 'img\login_to_template_manager.png', 'login_to_template_manager.png',
        'image/png', 'cid:login_to_template_manager.png');

    $attachment[] = PostmarkAttachment::fromFile(FCPATH . 'img\password_successfully_changed_message.png', 'password_successfully_changed_message.png',
        'image/png', 'cid:password_successfully_changed_message.png');
    return $attachment;
}

И:

public function sendEmailWithInlineAttachments($data) {
    $client = new PostmarkClient($this->api_key);
    return $client->sendEmailBatch([$data])[0];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...