Home » Php » php – How to display <iframe> tag to gmail

php – How to display <iframe> tag to gmail

Posted by: admin July 12, 2020 Leave a comment

Questions:

I use codeigniter to send email… After activating the user account it sends another email to insert tag but when the user receives the message, no tag appeared but when I tried using other elements like or it renders the style but how come doesn’t?

        $message = 'Congratulations! Use the script below to add your widget.<br>';
        $message .= "<iframe frameborder=\"0\" src=\"<?=base_url() ?>business/widget/{$id}\" height=\"320px;\" width=\"480px\" style=\"border: 1px solid #ccc;\"></iframe>";

        $this->email->message($message);    

        if($this->email->send())        
        { 
                         other code.... 
                    }
How to&Answers:

Gmail and many other email clients are very strict about what HTML you can use in your HTML emails.

<iframe> is strictly off limits, because it could expose the user to a website which they were not expecting, and the website at the other end could record info about the user (such as their IP address). Images are blocked for similar reasons.

If I were you, I’d stick to using super basic HTML and CSS. Focus on getting the message to the user and hope their client makes the message look pretty. Always offer a link to view the full message elsewhere.

Answer:

<iframe>s cannot be used in most email clients – whether in an application or as a website. They are either stripped for one of several reasons:

  • The mail/web client could have trouble rendering it, so it is excluded.
  • An <iframe> could be used for phishing/malicious attacks, putting malicious code in what was otherwise vetted and safe (the browser/client can’t see or scan what gets loaded into an iframe, it just loads it into the DOM).

An alternative, (what YouTube do), is instead of embedding something in an iframe (in their case, a video), they have an <a> wrapped around an <img> or thumbnail, which gives the impression that you are playing a video. All it does when you click on it, is it take you to that video’s URL.

If you were trying to put extensive code into the email, you could manually write it in. This however has other effects, as some other tags are limited/styling can be a big hassle for emails. AFAIK some HTML5 elements are also stripped from emails.

As Orangepill said, Campaign Monitor have done the legwork and provided a chart showing where iframes can be used. They also suggest to stay away from iframes.

A solution not mentioned would be to have an image, with a link at the bottom that says View this message in a webpage which will take the user to a page with the <iframe> working.