我正在尝试为我的管理员创建一个表单,这样他们就可以从我的网站上的管理面板中发送电子邮件。
我正在使用PHP mail.php和mime.php来发送电子邮件。我目前有一个基本的PHP脚本下面连同HTML。然而,我目前使用<textarea>
作为消息部分,因为Mail.php/mine.php
需要超文本标记语言,我该如何在每次管理员转到新行时添加<br>
标记呢?
PHP:
$SQL = $odb -> prepare("SELECT `name` FROM `staff_names` WHERE `username` = :username");
$SQL -> execute(array(':username' => $_SESSION['username']));
$name = $SQL -> fetchColumn(0);
if (isset($_POST['send-email'])){
if ($user -> isAdmin($odb)){
include('Mail.php');
include('Mail/mime.php');
// Constructing the email
$sender = "$name <".strtolower($_SESSION['username'].")@example.com>";// Your name and email address
$recipient = strip_tags(trim($_POST['email'])); // The Recipients name and email address
$subject = strip_tags(trim($_POST['subject']));// Subject for the email
$text = $_POST['message'];// Text version of the email
$html = $_POST['message'];// HTML version of the email
$crlf = "\r\n";
$headers = array('From' => $sender, 'Return-Path' => $sender, 'Subject' => $subject);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
// Sending the email
$mail =& Mail::factory('mail');
$mail->send($recipient, $headers, $body);
$notify = success("Email sent to {$_POST['email']} successfully.");
}
}
HTML:
<form class="form-horizontal push-10-t" method="post">
<div class="form-group row">
<div class="col-sm-12">
<div class="form-material">
<label for="email">Email</label>
<input class="form-control" type="email" id="email" name="email" placeholder="Enter the recipient email">
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<div class="form-material">
<label for="subject">Subject</label>
<input class="form-control" type="text" id="subject" name="subject" placeholder="Enter subject here">
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<div class="form-material">
<label for="message">Message</label>
<textarea class="form-control" type="textarea" rows="6" id="message" placeholder="Please type your message here" name="message"></textarea>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-9">
<button name="send-email" value="do" class="btn btn-sm btn-primary" type="submit">Send</button>
</div>
</div>
</form>
发布于 2018-06-01 05:38:18
有一个php函数可以将换行符转换为<br>
:看看nl2br()
https://stackoverflow.com/questions/50633140
复制相似问题