php - 使用 PHPmailer 从网站发送消息时遇到错误

标签 php html css

我正在尝试修复错误,但我做不到。互联网上有很多关于 PHPmailer 的资料我试过了,但我的网站不发送消息。请修正错误。我正在粘贴我的代码。也请告诉我其他发送消息的方法。

<div class="row">
    <div class="col-lg-8">
        <div class="boxed-grey">
            <form id="contact-form">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <form action="ContactFormHandler.php"
                                  method="post">
                                <label for="name">
                                    Name</label>
                                <input type="text" class="form-control"
                                       id="name" placeholder="Enter name" required="required" />
                        </div>
                        <div class="form-group">
                            <label for="email">
                                Email Address</label>
                            <div class="input-group">
                                 <span class="input-group-addon"><span
                                         class="glyphicon glyphicon-envelope"></span>
                                </span>
                                <input type="email"
                                       class="form-control" id="email" placeholder="Enter email"
                                       required="required" /></div>
                        </div>

                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="name">
                                Message</label>
                            <textarea name="message" id="message"
                                      class="form-control" rows="9" cols="25" required="required"
                                      placeholder="Message"></textarea>
                        </div>
                    </div>
                    require("path of phpmailer folder
                    \class.phpmailer.php");

                    $mail = new PHPMailer();

                    $mail->IsSMTP();
                    $mail->Host = "mymail.domain.com";
                    $mail->SMTPAuth = true;
                    $mail->Username = "myemail";
                    $mail->Password = "psswrd";

                    $mail->From = "you@domain.com";
                    $mail->FromName = "Your Name";
                    $mail->AddReplyTo("you@domain.com");
                    $mail->AddAddress("user@domain.com");
                    $mail->IsHTML(true);
                    $mail->Subject = "Test message sent using the
                    PHPMailer component";
                    $mail->Body = "This is a test message.";
                    $mail->Send();
                    ?>
                    <div class="col-md-12">
                        <button type="submit" class="btn btn-skin
pull-right" id="btnContactUs">
                            Send Message</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

最佳答案

您的姓名和电子邮件输入没有列出名称属性,因此不会在表单提交中发送任何数据。

您需要按如下方式更改它们:

<input type="text" class="form-control" name="name" id="name" placeholder="Enter name" required="required" />


<input type="email" class="form-control" name="email"  id="email"  placeholder="Enter email" required="required" />

这可能不是导致错误的问题,但它会导致问题。

关于php - 使用 PHPmailer 从网站发送消息时遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35833594/

相关文章:

PHP - 指定端口设置的 MySQL 连接

javascript - 文本较大时如何将文本移动到同一行的新行

html - 表格单元格垂直对齐问题

html - 在网格中围绕图像环绕文本

php - Laravel Blade 中 Label 标签中的单选按钮

php - stdClass 类的对象无法转换为字符串

php - 使用 Azure 和 PHP 进行 URL 映射

javascript - 如何消除这个 JQuery/CSS3 动画的闪烁

javascript - 如何使用 bootstrap carousel 最大化或填充整个页面。 (带导航栏)

html - 在 CSS 中嵌套 CSS