因此,我收到的电子邮件仅显示主题、发件人、收件人,但不显示发件人姓名或电话号码,这不是在本地完成的,而是从我的网站托管位置完成的。我希望它在正文后显示发件人的姓名和电话号码。这是我的代码:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require 'vendor/autoload.php';
$mail = new PHPmailer();
$mail->Host = "";
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPDebug = SMTP::DEBUG_OFF;
$mail->Username = "";
$mail->Password = "";
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->addAddress('');
$mail->setFrom($_POST['email']);
$mail->Subject = $_POST['subject'];
$mail->isHTML(true);
$mail->Body = $_POST['message'];
$mail->Name = $_POST['name'];
$mail->Phone = $_POST['number'];
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
//echo $mail->ErrorInfo;
?>
这是我的html:
<form action="contact.php" method="post" class="signin-form mt-lg-5 mt-4">
<div class="input-grids">
<input type="text" name="name" placeholder="Full name or Business"
class="contact-input" required=""/>
<input type="email" name="email" placeholder="Your email" class="contact-
input" required=""/>
<input type="text" name="subject" placeholder="Subject" class="contact-
input" required=""/>
<input type="text" name="number" placeholder="Phone number"
class="contact-input" />
</div>
<div class="form-input">
<textarea name="message" placeholder="Type your message here"
required=""></textarea>
</div>
<div class="form-input mb-5">
<label class="container"><p>Send me a copy <a href="#">privacy policy.
</a></p>
<input type="checkbox">
<span class="checkmark"></span>
</label>
</div>
<button class="btn submit">Submit</button>
</form>
然后给我的提交按钮这个属性
<button class="btn submit" name="submit">Submit</button>
最后一件事:我想表明该消息已发送到联系表单上方,而不是页面顶部,这不是首要任务,但我仍然想知道。
叮当猫咪
相关分类