使用PHP要求并修改HTML内容以将其发送为HTML- email



我正在使用phpmailer发送我的电子邮件。我创建了一个您输入一些详细信息的表格(包括电子邮件地址)。单击提交/生成后,我想使用表格详细信息来修改电子邮件的内容。电子邮件应显示为HTML电子邮件。但是,我只是无法获得正确显示的表格或让我的html email正确发送。

表单代码(index.php):

<?php
    //PHP mailer code
    require 'PHPmailer/PHPMailerAutoload.php';
    $emailmessage = require 'mail.php';
    $mail = new PHPMailer;
    //$mail->SMTPDebug = 3;                // Enable verbose debug output
    if (isset($_POST['submit'])) {
        $mail->isSMTP();                   // Set mailer to use SMTP
        $mail->Host = 'smtp.gmail.com';    // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;            // Enable SMTP authentication
        $mail->Username = 'email@email.com';    // SMTP username
        $mail->Password = 'password';      // SMTP password
        $mail->SMTPSecure = 'tls';   // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 587;                 // TCP port to connect to
        $mail->setFrom('email@email.com', 'Me');
        $mail->addAddress($_POST['emailrecipients'], $_POST['client']);  // Add a recipient
        $mail->isHTML(true);               // Set email format to HTML
        $mail->Subject = $_POST['callid'].' | Customer Feedback';
        $mail->Body    = $emailmessage;
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
        if(!$mail->send()) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
            echo 'Message has been sent';
        }
    }
?>
<!DOCTYPE html>
    <html>
        <body>
        <form>
            <input type="text" id="firstname" name="firstname" placeholder="John" />
            <input type="text" id="lastname" name="lastname" placeholder="Doe" />
            <input type="email" id="email" name="email" placeholder="email@email.com" />
            <button type="submit" name="submit">Generate</button>
        </form>
        </body>
    </html>`

电子邮件代码(mail.php):

<!DOCTYPE html>
<html>
<body>
<p>First Name: <?php $_POST['firstname']; ?></p>
<p>Last Name: <?php $_POST['lastname']; ?></p>
</body>
</html>

我想象,提交后,将根据输入字段更改所需的电子邮件,然后发送到键入电子邮件输入字段的地址。

我不确定此行是否按预期工作:

$emailmessage = require 'mail.php';

您应该有以下邮件。php:

    $emailmessage = "
        <!DOCTYPE html>
        <html>
        <body>
        <p>First Name:".$_POST['firstname']."</p>
        <p>Last Name:  ".$_POST['lastname']."</p>
        </body>
        </html>";

,然后仅使用

require "mail.php" 

在您的代码的第2行中。您还应该在HTML形式中添加"表单"标签。

最新更新