PHP表单提交成功消息在消息后插入不需要的数字

PHP表单提交成功消息在消息后插入不需要的数字

问题描述:

Created a php form with a success message that appears just below the Submit button upon successful mission. After adding some additional code in the php to create an email confirmation, I'm now noticing that a number "1" has been inserted in the line after my success message - see below:

enter image description here

Any ideas on how to make that number 1 go away? Code below:

<?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
 E-Mail: $email
 Phone: $phone
 Company: $company
   
Message:
 $message";

// Confirmation email.
$conf_subject = 'Your recent inquiry';

$conf_sender = 'MY SITE <no-reply@mysite.com>';

$msg =  $_POST['name'] . ",

Thank you for your recent inquiry. A member of 
our team will respond to your message as soon as possible.

Thanks,

My 
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&#33;</p>';
           echo (mail ($email, $conf_subject, $msg, 'From: ' . $conf_sender 
           ));
    } else { 
        echo '<p>Something went wrong, go back and try again&#33;</p>'; 
    } 
    } else if ($_POST['submit'] && $human != '4') {
        echo '<p>You answered the anti-spam question incorrectly&#33;</p>';
    }
    } else {
        echo '<p>You need to fill in all required fields&#33;</p>';
    }
}
?>

Thanks everyone!

 echo (mail ($email, $conf_subject, $msg, 'From: ' . $conf_sender ));

This code is causing the echo, its echoing 1 as the mail() function is returning true. I'm not sure why you're echoing the mail function here any way, just remove the echo and all is good.

This line:

echo (mail ($email, $conf_subject, $msg, 'From: ' . $conf_sender));

You are echoing out the result of your call to the mail function. Since the mail was successfully handed over to the server it returns true. When you echo out a boolean true it gets converted to an integer which is 1. That's why you see that in your code.

Remove the echo to remove the 1 from being displayed in your output.

That is because of this code:

echo (mail ($email, $conf_subject, $msg, 'From: ' . $conf_sender ));

You "echo" the result of the mail function. "1" is equal to "true" on mail sending success.