dongpaipu8394 2011-02-02 05:52
浏览 36
已采纳

php电子邮件使用mysql,html和imbedding图像

I need to send a daily email based on data in mysql database which updates every day. I need it to be in html so that I can put links in there. I will also use images in the email. The basic structure will be:

Here's the list:

Business name (which is a link) Short description Image (which is a link)

Business name (which is a link) Short description Image (which is a link) . . .

All the data is in mySQL database (although the "image" in the database is a reference to a file eg /images/business/image.jpg)

My questions is should I be using phpmailer (I've never used it before) or using something like this:

//set up msg

$msg = "<html><body>Here's the list: <br /><br />";
while($i<numofelementsindb){
    $business=mysql_result($result, $i,"business");
    $description=mysql_result($result, $i,"description");
    $msg .= "The business name is <a href='www.example.com'><b>{$business}</b></a> does {$description}<br />
";
    $i++;
}
$msg .= "</body>
</html>"; 

//send  

I also don't know how to imbed the image in the email either so any advice would be appreciated.
Do you have any safety suggestions as well?

Thanks

  • 写回答

2条回答 默认 最新

  • dongwu5801 2011-02-02 09:37
    关注

    Using a mime email class I've written, here's the code to do what you wanted:

    require 'class.omime.php';
    $email = new omime('related');
    
    $html = "<html><body>Here's the list: <br /><br />";
    while($i < numofelementsindb) {
        $business    = mysql_result($result, $i,"business");
        $description = mysql_result($result, $i,"description");
        $imageFilePath = ''; # path to image file
    
        $cid = $email->attachFile($imageFilePath);
        $html.= "The business name is <a href='www.example.com'><strong>{$business}</strong></a> does {$description}<br />
    ";
        $html.= "<img src=\"cid:{$cid}\" alt=\"Image of {$business}\"/><br /><br />
    ";
        $i++;
    }
    $html.= "</body></html>";
    
    $email->attachHTML($html);
    $email->send('recipient@email.com', 'Daily List of Businesses', 'from: sender@email.com');
    

    All the images will be attached with the email so you won't have to place them on a webserver. Recipient will still be asked if they want to display the images. Check the omime source page if you're interested.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程