猿问

带有 HTML 联系表的 PHPMailer

抱歉我的英语不好 :( 我在这里遇到了一个大问题,我有带有联系表格的 html 主页。我想用 PHPMailer 发送这个表格,当我发送消息时我得到这个但没有文本:/ 我明白了只有像“这里是主题”这样的示例文本。有人可以帮我吗?


这是 phpmailer.php 代码:


<?php

use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;


require 'src/Exception.php';

require 'src/PHPMailer.php';

require 'src/SMTP.php';


$mail = new PHPMailer(true);                              // Passing `true` enables exceptions

try {

    //Server settings

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

    $mail->isSMTP();                                      // Set mailer to use SMTP

    $mail->Host = 'smtp.test.de';  // Specify main and backup SMTP servers

    $mail->SMTPAuth = true;                               // Enable SMTP authentication

    $mail->Username = 'MY EMAIL';                 // SMTP username

    $mail->Password = 'MY PASSWORT!';                           // SMTP password

    $mail->SMTPSecure = 'ssl';                           // Enable TLS encryption, `ssl` also accepted

    $mail->Port = 465;                                    // TCP port to connect to


    //Recipients

    $mail->setFrom('MY EMAIL');

    $mail->addAddress('MY EMAIL');     // Add a recipient




    //Content

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

    $mail->Subject = 'Here is the subject';

    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';


    $mail->send();

    echo 'Message has been sent';

} catch (Exception $e) {

    echo 'Message could not be sent.';

    echo 'Mailer Error: ' . $mail->ErrorInfo;

}

?>

我的电子邮件只是为了安全起见


慕码人8056858
浏览 72回答 1
1回答

鸿蒙传说

您需要在 PHPmailer 脚本中添加变量 $_POST :&nbsp; <?php&nbsp; &nbsp; use PHPMailer\PHPMailer\PHPMailer;&nbsp; &nbsp; use PHPMailer\PHPMailer\Exception;&nbsp; &nbsp; require 'src/Exception.php';&nbsp; &nbsp; require 'src/PHPMailer.php';&nbsp; &nbsp; require 'src/SMTP.php';&nbsp; &nbsp; $mail = new PHPMailer(true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Passing `true` enables exceptions&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; //Server settings&nbsp; &nbsp; &nbsp; &nbsp; $mail->SMTPDebug = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Enable verbose debug output&nbsp; &nbsp; &nbsp; &nbsp; $mail->isSMTP();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set mailer to use SMTP&nbsp; &nbsp; &nbsp; &nbsp; $mail->Host = 'smtp.test.de';&nbsp; // Specify main and backup SMTP servers&nbsp; &nbsp; &nbsp; &nbsp; $mail->SMTPAuth = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Enable SMTP authentication&nbsp; &nbsp; &nbsp; &nbsp; $mail->Username = 'MY EMAIL';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// SMTP username&nbsp; &nbsp; &nbsp; &nbsp; $mail->Password = 'MY PASSWORT!';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// SMTP password&nbsp; &nbsp; &nbsp; &nbsp; $mail->SMTPSecure = 'ssl';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Enable TLS encryption, `ssl` also accepted&nbsp; &nbsp; &nbsp; &nbsp; $mail->Port = 465;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // TCP port to connect to&nbsp; &nbsp; &nbsp; &nbsp; //Recipients&nbsp; &nbsp; &nbsp; &nbsp; $mail->setFrom('MY EMAIL');&nbsp; &nbsp; &nbsp; &nbsp; $mail->addAddress($_POST['mail']);&nbsp; &nbsp; &nbsp;// Add a recipient&nbsp; &nbsp; &nbsp; &nbsp; //Content&nbsp; &nbsp; &nbsp; &nbsp; $mail->isHTML(true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set email format to HTML&nbsp; &nbsp; &nbsp; &nbsp; $mail->Subject = $_POST['subject'];&nbsp; &nbsp; &nbsp; &nbsp; $mail->Body&nbsp; &nbsp; = $_POST['text'];&nbsp; &nbsp; &nbsp; &nbsp; $mail->send();&nbsp; &nbsp; &nbsp; &nbsp; //echo 'Message has been sent';&nbsp; &nbsp; &nbsp; &nbsp; header('Location: http://www.example.com/contact.php');&nbsp; &nbsp; &nbsp; &nbsp; exit();&nbsp; &nbsp; } catch (Exception $e) {&nbsp; &nbsp; &nbsp; &nbsp; echo 'Message could not be sent.';&nbsp; &nbsp; &nbsp; &nbsp; echo 'Mailer Error: ' . $mail->ErrorInfo;&nbsp; &nbsp; }&nbsp; &nbsp; ?>
随时随地看视频慕课网APP
我要回答