创建一个带有成功消息的php表单,该消息在成功执行任务后出现在Submit按钮下方。在php中添加一些额外的代码以创建电子邮件确认后,我现在注意到一个数字" 1"在我的成功消息之后插入了行 - 见下文:
关于如何使这个数字1消失的任何想法?代码如下:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$company = $_POST['company'];
$message = $_POST['message'];
$human = $_POST['human'];
$from = 'From: Page Name';
$to = 'email@mysite.com';
$subject = 'Service Inquiry';
$body = "From: $name\n E-Mail: $email\n Phone: $phone\n Company: $company\n
Message:\n $message";
// Confirmation email.
$conf_subject = 'Your recent inquiry';
$conf_sender = 'MY SITE <no-reply@mysite.com>';
$msg = $_POST['name'] . ",\n\nThank you for your recent inquiry. A member of
our team will respond to your message as soon as possible.\n\nThanks,\n\nMy
Company Team";
if ($_POST['submit']) {
if ($name != '' && $email != '' && $phone != '' && $message != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thanks for your inquiry, we will get back to you as soon
as we can!</p>';
echo (mail ($email, $conf_subject, $msg, 'From: ' . $conf_sender
));
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!</p>';
}
}
?>
谢谢大家!
答案 0 :(得分:1)
这一行:
echo (mail ($email, $conf_subject, $msg, 'From: ' . $conf_sender));
您正在回应调用邮件功能的结果。由于邮件已成功移交给服务器,因此返回true。当你回显一个布尔值true
时,它会被转换为一个1
的整数。这就是你在代码中看到的原因。
删除echo
以删除输出中显示的1
。
答案 1 :(得分:0)
echo (mail ($email, $conf_subject, $msg, 'From: ' . $conf_sender ));
此代码导致echo,其回显为1,因为mail()函数返回true。我不知道为什么你在这里以任何方式回应邮件功能,只需删除回声,一切都很好。
答案 2 :(得分:-1)
这是因为这段代码:
echo (mail ($email, $conf_subject, $msg, 'From: ' . $conf_sender ));
你“回应”邮件功能的结果。邮件发送成功时“1”等于“true”。