📜 ⬆️ ⬇️

Adding a Youtube video to an email newsletter

The video broke into the life of the Internet suddenly and, not to say so long ago. However, it has already become an integral part of the life of any of us. Video has become a business tool in the promotion of goods and services. You can find product instructions, promo videos, webinar recordings, etc. on Youtube. Placing video in email newsletters is a very sensible marketing move. According to our statistics, this is a 17% increase in the proportion of clicks in your newsletter (compared with similar without video).

But how to do it in your mailing list layout?

Embedding videos from Youtube on web pages is simple - just copy the html-code from the iframe and place it in yourself. But with the email-mailing such a trick will not work. And, although, email-mailing also contains a html-layout iframe can not be inserted into it for security reasons. Open the Technical and Administrative Requirements for sending emails to Mail.Ru. We use them as the main ones on the Runet market (Mail accounts for more than 70% of our traffic).

... when using HTML in your posts, make sure that the valid structure of the HTML document is respected. It is forbidden to use potentially dangerous objects, such as ActiveX, JavaScript, VBScript, Java applets, Frames and IFrames, connected from external CSS sites, Meta Refresh, etc. (the use of such elements may lead to blocking of your mailings);

')
In addition, such iframe will often simply be incorrectly displayed by email clients, programs or web services. And, nevertheless, how to insert a video into a letter? Email marketing service Pechkin-mail.ru, as always, does all the basic work for you.


The only effective way is to place a picture with an active link to the video in the form of a screenshot of your video with the Play button on top of it. For example, it might look like this:



Indeed, simply and efficiently. The only drawback is to manually remove such a screenshot is a chore and takes some time. Pechkin proposed a function to add a video in 2 clicks: you simply click on the “Video” block, insert a link to it and click “Paste”. After that, a screenshot of your video will appear in the layout you are creating with the Play button already superimposed and a link to the video on Youtube.

How is this implemented with us?

Pechkin always tries to help developers if they are faced with the same questions, and therefore now we will tell about the algorithm:
  1. Parsing the link from youtube, checking its validity to get the video ID out.
  2. Take a screenshot of youtube on average quality. This can be done simply by reference: img.youtube.com/vi/%YOUTUBE_ID%/hqdefault.jpg
  3. Overlay the image of the “apple-like” Play button with the PHP function.
  4. We post it in the cloud storage Selectel, get a link to the image, insert it into the newsletter.
  5. We are happy user.


Here is an example of a function in PHP that is used by us:

/** *    youtube    play * * @param $youtube_id Id of youtube-video url,    youtube,  rutube  vimeo * * @return * Url  (480360px)  selectel   ,  -    * OR FALSE if error */ function youtube_thumbnail_with_play($youtube_id,$url = '') { //     youtube? if ($youtube_id === '0'){ if(stripos($url,'rutube.ru') !== FALSE){ preg_match("/http:\/\/rutube.ru\/video\/(\w+)\//",$url,$matches); $xml_info = simplexml_load_file("http://rutube.ru/cgi-bin/xmlapi.cgi?rt_mode=movie&rt_movie_id=".$matches[1]."&utf=1"); if ($xml_info) { $thumbnail_url = (string) $xml_info->thumbnail_url; } }elseif(stripos($url,'vimeo.com') !== FALSE){ if ((stripos($url,'https') !== FALSE)) {$vimeo_id = substr($url,18);} else {$vimeo_id = substr($url,17);} $xml_info = simplexml_load_file("http://vimeo.com/api/v2/video/$vimeo_id.xml"); if ($xml_info) { $thumbnail_url = (string) $xml_info->video->thumbnail_large; } }else{ return FALSE; } }else{ $thumbnail_url = 'http://img.youtube.com/vi/'.$youtube_id.'/hqdefault.jpg'; } // Make sure the imagecopymerge() function exists (in GD image library). if (!function_exists('imagecopymerge')) { return FALSE; } $image = imagecreatefromjpeg($thumbnail_url); if (!$image) {return FALSE;} $image_size = getimagesize($thumbnail_url); // Calculate the proper coordinates for placing the play button in the middle. $destination_x = ($image_size[0] / 2) - 35; $destination_y = ($image_size[1] / 2) - 35; // Load the play button image. $play_button_image = imagecreatefrompng($root.'/images/play_button.png'); imagealphablending($play_button_image, TRUE); // Preserve transparency. imagealphablending($image, TRUE); // Preserve transparency. // Use imagecopy() to place the play button over the image. imagecopy( $image, // Destination image. $play_button_image, // Source image. $destination_x, // Destination x coordinate. $destination_y, // Destination y coordinate. 0, // Source x coordinate. 0, // Source y coordinate. 70, // Source width. 70 // Source height. ); if (is_dir($root.'/html/other/')===false){ mkdir($root.'/html/other/'); } $rand_path = $root.'/html/other/'.md5(time().rand(0,100000)).'.png'; imagepng($image,$rand_path); $selectel_str = $wizard->cloud_upload($rand_path); //       selectel if (strpos($selectel_str, 'http://static1.pechkin-mail.ru/') !== false) {unlink($rand_path);} imagedestroy($image); imagedestroy($play_button_image); return $selectel_str; } 


Here such small, but very convenient functionality turned out. Pechkin users now download videos from Youtube, Vimeo and Rutube to their email newsletters without any problems, increase the effectiveness of their sales, and we get from them the rays of goodness and joy from using the service.

Source: https://habr.com/ru/post/226157/


All Articles