本文整理汇总了PHP中Swift_Mime_Message::embed方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Mime_Message::embed方法的具体用法?PHP Swift_Mime_Message::embed怎么用?PHP Swift_Mime_Message::embed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Mime_Message
的用法示例。
在下文中一共展示了Swift_Mime_Message::embed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* {@inheritdoc)
*/
public function transform(\Swift_Mime_Message $message)
{
$body = $message->getBody();
$body = preg_replace_callback('/(src|background)="(http[^"]*)"/', function ($matches) use($message) {
$attribute = $matches[1];
$imagePath = $matches[2];
if ($fp = fopen($imagePath, "r")) {
$imagePath = $message->embed(\Swift_Image::fromPath($imagePath));
fclose($fp);
}
return sprintf('%s="%s"', $attribute, $imagePath);
}, $body);
$body = preg_replace_callback('/url\\((http[^"]*)\\)/', function ($matches) use($message) {
$imagePath = $matches[1];
if ($fp = fopen($imagePath, "r")) {
$imagePath = $message->embed(\Swift_Image::fromPath($imagePath));
fclose($fp);
}
return sprintf('url(%s)', $imagePath);
}, $body);
$message->setBody($body, 'text/html');
}
示例2: embedData
/**
* {@inheritdoc}
*/
public function embedData(string $data, string $name, string $contentType = null) : string
{
$image = Swift_Image::newInstance($data, $name, $contentType);
return $this->swift->embed($image);
}
示例3: pictureEmbed
/**
* Embed pictures
*
* @param \Swift_Mime_Message $message E-mail message
*
* @access public
* @return void
* @author Etienne de Longeaux <etienne.delongeaux@gmail.com>
*/
public function pictureEmbed(\Swift_Mime_Message &$message)
{
$body = $message->getBody();
$body = preg_replace_callback('/(src|background)="(http[^"]*)"/', function ($matches) use($message) {
$attribute = $matches[1];
$imagePath = $matches[2];
if ($fp = fopen($imagePath, "r")) {
// You can embed files from a URL if allow_url_fopen is on in php.ini
$imagePath = $message->embed(\Swift_Image::fromPath($imagePath));
fclose($fp);
}
return sprintf('%s="%s"', $attribute, $imagePath);
}, $body);
$body = preg_replace_callback('/url\\((http[^"]*)\\)/', function ($matches) use($message) {
$imagePath = $matches[1];
if ($fp = fopen($imagePath, "r")) {
// You can embed files from a URL if allow_url_fopen is on in php.ini
$imagePath = $message->embed(\Swift_Image::fromPath($imagePath));
fclose($fp);
}
return sprintf('url(%s)', $imagePath);
}, $body);
$message->setBody($body, 'text/html');
}