dongyukui8330 2017-05-10 14:57
浏览 53
已采纳

如何发送包含DATETIME的PHP电子邮件?

I have this piece of code here which sends an auto-reply to customers depending on their email request. I am trying to include a section of text which looks like this:

"This email was sent at: dd/M/yyyy - hh:ii tt"

Here is my code, located within is the parts where I want to call this date using PHP and will display once received, inside [ ].

    <?php

require 'class.phpmailer.php';
require 'PHPMailerAutoload.php';

    // Set the variables from the form
    $firstName = $_POST['firstName'];
    $lastName = $_POST['lastName'];
    $telephone = $_POST['telephone'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $date = $_POST["2017"];

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                                 // Enable verbose debug output

$mail->isSMTP();                                        // Set mailer to use SMTP
$mail->Host = '***';            // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                                 // Enable SMTP authentication
$mail->Username = '***';    // SMTP username
$mail->Password = '***';                            // SMTP password
$mail->SMTPSecure = 'ssl';                              // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                      // TCP port to connect to

$mail->setFrom('***', '***');
$mail->addAddress('**');                  // Add a recipient

//$mail->addAddress('ellen@example.com');                         // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz');                   // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');              // Optional name

$mail->isHTML(true);                                                  // Set email format to HTML

$mail->Subject = '***';
$mail->Body    = $message;

$message = '<b>First Name: </b>'.$_POST['firstName'].' 
 <br><br><b>Last Name: </b>'.$_POST['lastName'].' 
 <br><br><b>Telephone: </b>'.$_POST['phone'].' 
 <br><br><b>Email: </b>'.$_POST['email'].' 
 <br><br><b>Message: </b>'.$_POST['message']; 

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been Sent';
}

if ($mail->send()){  
  $autoemail = new PHPMailer();  
  $autoemail->From = '***';  
  $autoemail->FromName = '***';  
  $autoemail->AddAddress($email); 
  $autoemail->Subject = 'Autoreply: Enquiry Submitted';  
  $autoemail->Body = '<html><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Email Confirmation</title>


<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  </head>
  <body>
    <div class="container-full">
    <div class="row">
            <div class="col-md-12" style="padding: 30;">
                <div class="card">
                    <div class="card-img-top"><h2 align="center">Your Latest Enquiry</h2>
                    <div class="card-block">
                        <h4 class="card-title mt-3" align="center">Hi '.$_POST["firstName"].',</h4>
                        <div class="card-text">
                            <p align="center">Thank you for your Enquiry, we aim to give a response as quick as possible.<br/>On the term that we have forgotten to contact you within 48hrs, please give us a <b><u><a href="http://www.allensautocleanse.co.uk/contact">call</a></u></b>.</p>
                        </div>
                    </div>
                    <div class="card-footer" align="center">
                        <small>This email was sent at: **[CURRENT DATETIME INSERTED HERE!]**</small> 
                    </div>
                </div>
            </div>
        </div> 
    </div>
    <footer>
    <div class="col-md-6">
    <p>Copyright &copy; <b>**** - **[CURRENT YEAR INSERTED HERE!]**</p> 
    </b>
    </div>
    </footer>
</div>
</body>
  </html>';
  $autoemail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

    //Call the auto send method 
   $autoemail->Send();  
}  

?>
  • 写回答

1条回答 默认 最新

  • dpzjl68484 2017-05-10 15:06
    关注

    try the date function

    <small>This email was sent at: **[<?php echo date("dd/M/YY HH:i:s");]**</small> 
    

    you can look up the different formats at

    https://www.w3schools.com/php/func_date_date.asp

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?