亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

帶有 HTML 聯系表的 PHPMailer

帶有 HTML 聯系表的 PHPMailer

PHP
慕碼人8056858 2022-07-22 11:00:09
抱歉我的英語不好 :( 我在這里遇到了一個大問題,我有帶有聯系表格的 html 主頁。我想用 PHPMailer 發送這個表格,當我發送消息時我得到這個但沒有文本:/ 我明白了只有像“這里是主題”這樣的示例文本。有人可以幫我嗎?這是 phpmailer.php 代碼:<?phpuse 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 exceptionstry {    //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;}?>我的電子郵件只是為了安全起見
查看完整描述

1 回答

?
鴻蒙傳說

TA貢獻1865條經驗 獲得超7個贊

您需要在 PHPmailer 腳本中添加變量 $_POST :


  <?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($_POST['mail']);     // Add a recipient




        //Content

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

        $mail->Subject = $_POST['subject'];

        $mail->Body    = $_POST['text'];


        $mail->send();

        //echo 'Message has been sent';

        header('Location: http://www.example.com/contact.php');

        exit();

    } catch (Exception $e) {

        echo 'Message could not be sent.';

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

    }

    ?>


查看完整回答
反對 回復 2022-07-22
  • 1 回答
  • 0 關注
  • 89 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號