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 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动