duannuochi3549 2016-08-17 15:03
浏览 29
已采纳

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!

  • 写回答

3条回答 默认 最新

  • dongzhilian0188 2016-08-17 15:05
    关注
     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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?