alega
alega

Reputation: 97

send iframe with youtube in email body

i want to send some html in email body, but gmail doesn't interpret iframe tag with youtube video. Is it because of security violations or other reasons?

here is my code:

    this->load->library('email');       
    $config['mailtype'] = 'html';
    $config['wordwrap'] = TRUE;
    $this->email->initialize($config);
        $this->email->from('<email>', 'Alega');
        $this->email->to('<email>'); 
        $this->email->subject('Email Test');
        $this->email->message('<iframe title="YouTube video player" width="480" height="390" src="<url>" frameborder="0" allowfullscreen></iframe>');   

            $this->email->send();

Upvotes: 7

Views: 7219

Answers (2)

Nikunj Dhimar
Nikunj Dhimar

Reputation: 2386

Many email servers won't allow this due to security reason. But you can try these following solutions.

Solution 1:

    $var = html_escape('<iframe title="YouTube video player" width="480" height="390" src="<url>" frameborder="0" allowfullscreen></iframe>');
    $this->email->message($var);

Solution 2:

$this->email->message('<&nbs;iframe title="YouTube video player" width="480" height="390" src="<url>" frameborder="0" allowfullscreen><&nbs;/iframe>');

However, in solution 2 you need to inform the receiver to remove space from a tag.

Upvotes: 0

Dunhamzzz
Dunhamzzz

Reputation: 14808

It's because of security, it's the same reason you can't put javascript or anything external other than images in an email either - it can give the email too much 'power'. (You can put stuff there, it wont be displayed). Sadly this means no reliable flash support either.

In fact, most email readers will not parse even simple tags or CSS because of lack of support, I actually revert to tables just to make sure that the email looks consistent across all the different email clients out there.

Your best/only option is to just link to the video I'm afraid. As mentioned above, Gmail will parse the Youtube links and actually embed them for people who have it enabled.

Upvotes: 7

Related Questions