duanquannan0593 2010-12-20 08:02
浏览 7
已采纳

使用php创建动态附件

i am doing mail concepts. in this i want to send a dynamic attachments with email. actually user gets email with attachment. this attachment will be dynamic. how to create dynamic attachment for email.i tried this. but no use. anybody help.

i have 'attachments.txt'file with content

User Name: <<name>>
Designid:<<designid>>
Designname:<<designname>>
Orderid:<<orderid>>

i was updated this file as

$myfile = "attachments.txt";
$fh = fopen($myfile, 'w') or die("can't open file");
$stringData = str_replace("<<name>>", $fetuser[firstname], $fh);
//echo $fetuser[firstname];exit;
fwrite($fh, $stringData);
$stringData = str_replace("<<designid>>",$_SESSION[designid], $fh);
fwrite($fh, $stringData);
$stringData = str_replace("<<designname>>", $fetch_designname[designtype], $fh);
fwrite($fh, $stringData);
$stringData = str_replace("<<orderno>>", $ordno, $fh);
fwrite($fh, $stringData);
fclose($fh);

finally i was added attachment in mail like this $mail->AddAttachment("$myfile");

but this is not working properly. anybody help.

  • 写回答

2条回答 默认 最新

  • douyueqing1530 2010-12-20 08:39
    关注

    I don't think you can pass a file handler to str_replace like that. Read in the contents first, replace your placeholders, and then write the file again. Also, if you write this to the same file containing your template, it will no longer be a template the second time you want to send an email, but I'm sure you thought of something for that :)

    EDIT:

    So, you can do someting like this:

    $text = file_get_contents($templateFile);
    
    // perhaps some error handling here
    
    $text = str_replace(array('<<name>>', '<<designid>>', '<<designname>>', '<<orderid>>'),
                        array($fetuser[firstname], $_SESSION[designid], $fetch_designname[designtype], $ordno),
                        $text);
    
    file_put_contents($attachmentFile, $text);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据