【发布时间】:2014-05-24 14:34:33
【问题描述】:
我正在使用 wordpress cms 和 PHPMailer。在我的表单处理器中,我有一个简单的循环,它生成一组选定的图像。请检查下面的相关代码块。它基本上根据通过表单提供的帖子 ID 生成图像数组。我需要提取所有这些图像并将它们嵌入电子邮件正文中。请注意,我不打算将这些图像作为附件发送。这是一个剥离的代码版本。
$email = new PHPMailer();
$email->From = 'John@example.com';
$email->FromName = 'John Doe';
$email->Subject = 'This is the subject of the message';
$body = '<table><tr><td>';
$body .=
$args = array('post__in' => $short_ids, 'post_type' => 'post');
$posts = get_posts($args);
foreach ($posts as $post) : ?>
<?php $images = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'cover' );
$img_url = $images[0];
$email->AddEmbeddedImage($img_url, '1243');?>
<img src="cid:1243"/>
<?php endforeach;?>
$body = '</td></tr></table><tr>';
$email->MsgHTML($body);
$email->IsHTML(true);
$email->AddAddress( 'email@gmail.com' );
$email->Send();
我刚刚在电子邮件正文中看到了
Array这个词。如何将此数组 > 转换为要嵌入电子邮件正文的图像?所以我想我基本上需要数组操作方面的帮助。
更新:这是我想出的另一个代码,它成功地从数组中获取图像并实际回显到页面上,但 不嵌入图像电子邮件正文。
foreach ($posts as $post) : ?>
<?php $images = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'cover' );
$img_urls = $images[0]; ?>
<img src="<?php echo $img_urls;?>">
<?php endforeach;
【问题讨论】: