检索包含日期和时间的电子邮件

时间:2015-12-26 20:45:14

标签: php mysql

我有一个小形式,由于某种原因,一切都很好用一个小问题。当您收到来自表单的电子邮件时,日期将不会显示在发送的电子邮件中,如何显示并发送到数据库..电子邮件中的IP显示没问题。

$message = "Welcome\n\n\n\nThank you for registering, if you have received this email then you have successfully created your new account. This message was sent from an unmonitored account. Any responses will not be read.\n\nRequest made from: " . $ip = $_SERVER['REMOTE_ADDR'];
' on ' . $date = date('Y/m/d H:i:s');

$additional_headers = "From: $from\nReply-To: $from\nContent-Type: text/plain";

mail($to, $subject, $message, $additional_headers);

1 个答案:

答案 0 :(得分:0)

电子邮件中未显示日期的原因是特定行未连接到任何内容。

$message = "Welcome\n\n\n\nThank you for registering, if you have received this email then you have successfully created your new account. This message was sent from an unmonitored account. Any responses will not be read.\n\nRequest made from: " . $ip = $_SERVER['REMOTE_ADDR'];
        ' on ' . $date = date('Y/m/d H:i:s');

应该是:

$message = "Welcome\n\n\n\nThank you for registering, if you have received this email then you have successfully created your new account. This message was sent from an unmonitored account. Any responses will not be read.\n\nRequest made from: " . $ip = $_SERVER['REMOTE_ADDR'] . " on " . $date = date('Y/m/d H:i:s');

IP部分后面有分号,并且您的日期不会连接到字符串上。当前使用假IP回应您的$message变量会返回:

  

欢迎感谢您注册,如果您收到此电子邮件   然后您已成功创建新帐户。这条消息是   从不受监控的帐户发送。任何回复都不会被阅读。   请求来自:0.0.0.0

并使用我的代码建议它返回:

  

欢迎感谢您注册,如果您收到此电子邮件   然后您已成功创建新帐户。这条消息是   从不受监控的帐户发送。任何回复都不会被阅读。   请求来自:0.0.0.0 on 2015/12/26 14:59:56

PS:我还将'字符更改为",一致性提高了可读性。