将日期+时间插入电子邮件的主题

时间:2013-01-26 21:44:49

标签: php email sendmail

如何在主题开头插入日期和时间,例如

代码中的日期('d-m-Y h:m:s')不起作用并返回此错误:解析错误:语法错误,意外T_STRING

<?php
    mail('joe@example.com', '"date('d-m-Y h:m:s')" Daily Backup: example.com', 'Download your daily backup from this link: http://example.com/backups/backup.zip');
?>

此代码有效:(没有日期和时间)

<?php
    mail('joe@example.com', 'Daily Backup: example.com', 'Download your daily backup from this link: http://example.com/backups/backup.zip');
?>

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

您错过了将您的php代码封装在字符串中:

mail('joe@example.com', '"'.date('d-m-Y h:m:s').'" Daily Backup: example.com', 'Download your daily backup from this link: http://example.com/backups/backup.zip');

答案 1 :(得分:0)

它看起来像语法错误。尝试在开始字符串之前放置日期函数,使其变为

<?php
    mail('joe@example.com', date('d-m-Y h:m:s').' Daily Backup: example.com', 'Download your daily backup from this link: http://example.com/backups/backup.zip');
?>