gpt4 book ai didi

带有 HTML 联系表单的 PHPMailer

转载 作者:行者123 更新时间:2023-12-04 10:45:00 25 4
gpt4 key购买 nike

对不起我的英语不好:(我在这里遇到了一个大问题,我有一个带有联系表格的 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;
}
?>

我的邮箱只是为了安全

这是来自 html 联系表单的代码:

<!-- Contact Form -->
<div class="row">
<div class="col-md-8 col-md-offset-2">

<form action="phpmailer_new.php" method="POST">
<div class="form-group">
<input type="text" name="mail" class="form-control" placeholder="Email Address">
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group">
<textarea class="form-control" name="text" rows="3" placeholder="Your Message"></textarea>
<button class="btn btn-default" type="submit">Send Message</button>
</div>
</form>
</div>
</div>
<!-- End Contact Form -->

干杯伊夫

最佳答案

您需要在 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;
}
?>

关于带有 HTML 联系表单的 PHPMailer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59746993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com