【发布时间】:2020-05-01 23:01:12
【问题描述】:
对不起我的英语不好:( 我在这里遇到了一个大问题,我在那里有带有联系表格的 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为什么不试试php的mail功能? php.net/manual/en/function.mail.php -
我认为我没有足够的知识来做到这一点。 xD
-
不,不要使用
mail();使用它来生成和发送有效的电子邮件要困难得多,it's prone to vulnerabilities。 PHPMailer 默认充当mail()的前端并处理它导致的问题,但通过 SMTP 发送更快更安全。
标签: php html phpmailer contact-form