为了账号安全,请及时绑定邮箱和手机立即绑定

PHPMailer with HTML Contact Form

PHPMailer with HTML Contact Form

PHP
缥缈止盈 2022-08-05 10:49:17
对不起,我的英语不好:(我在这里遇到了一个大问题,我有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 回答

?
慕雪6442864

TA贡献1812条经验 获得超5个赞

您需要在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-08-05
  • 1 回答
  • 0 关注
  • 90 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号