0

我正在尝试为我的管理员创建一个表单,以便他们能够从我网站的管理面板中发送电子邮件。

我正在使用 PHP mail.php 和 mime.php 发送电子邮件。我目前在下面有一个基本的 PHP 脚本以及 HTML。但是,我目前<textarea>用于消息部分,因为需要 HTML每次管理员进入新行时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>
4

1 回答 1

0

有一个 php 函数可以将换行符转换为<br>:看看nl2br()

于 2018-05-31T21:38:18.303 回答