免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2662 | 回复: 6

php Mailer中如何发送带日期变量的附件? [复制链接]

论坛徽章:
0
发表于 2011-09-19 11:57 |显示全部楼层
本帖最后由 moshangxie 于 2011-09-19 12:01 编辑

小弟刚接触php,弱弱地问问
php Mailer 发送邮件时如何将某一路径下,带有当天日期戳的附件发送出去
即:
  1. $mail->AddAttachment("/opt/sendmail/log/modify-20110919.rar");
复制代码
其中20110919为变量,能够根据日期变化,请问如何实现?

还有如果从一个文本文件读取内容,如何将内容读取到 发信内容中
谢谢

论坛徽章:
0
发表于 2011-09-19 13:00 |显示全部楼层
回复 2# sunicc_


    我在前面定义如下:
  1. $date= `date '+%Y%m%d'`;
复制代码
然后定义 上传附件
  1. $mail->AddAttachment("/opt/sendmail/log/modify-$date.rar");   
复制代码
而且存在着modify-20110919.rar 文件
邮件发出去了,但附件中没有东西?

论坛徽章:
0
发表于 2011-09-19 13:38 |显示全部楼层
原因好像找到了
在前面定义
$file="/opt/sendmail/log/ldap_modify-$date.rar";
echo $file;
结果成这样了
  1. [root@NOM mailer]# php ./mail.php

  2. 20110919
  3. /opt/sendmail/log/modify-20110919
  4. .rarMessage has been sent[root@NOM mailer]#
复制代码
将..rar下移了一行
不知道为什么会这样

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:55:28
发表于 2011-09-19 14:52 |显示全部楼层
原因好像找到了
在前面定义
$file="/opt/sendmail/log/ldap_modify-$date.rar";
echo $file;
结果成这样 ...
moshangxie 发表于 2011-09-19 13:38



楼主写shell写习惯了吧?
php有自己的date函数的,不需要调sh的,sh的date后面会有换行符的。

论坛徽章:
0
发表于 2011-09-19 16:08 |显示全部楼层
<?php
echo date("Y/m/d");
echo "<br />";
echo date("Y.m.d");
echo "<br />";
echo date("Y-m-d");
?>

以上代码的输出类似这样:

2006/07/11
2006.07.11
2006-07-11

论坛徽章:
0
发表于 2011-09-19 16:18 |显示全部楼层
本帖最后由 moshangxie 于 2011-09-19 16:27 编辑

回复 5# xinglu1983


    确实些shell习惯了,对PHP也不熟悉
  以日期为变量的文件名确实写不出来
汗[code]
$mail->FromName = "test";
$mail->AddAddress("test@126.com", "test");            
$date= date("Ymd");
echo $date;
$mail->WordWrap = 50;     
$mail->AddAttachment("/opt/sendmail/log/ldap_modify-$date.rar");        添加附件 绝对路径+日期变量的文件名
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = "modify-$date  is OK!!!";  
$mail->Body    = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:55:28
发表于 2011-09-19 16:20 |显示全部楼层
回复 7# moshangxie
  1. $date= date('Ymd');
  2. $mail->AddAttachment("/opt/sendmail/log/modify-$date.rar");   
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP