How can I send a copy of a PHP / HTML form to the sender's email address?

前端 未结 1 390
失恋的感觉
失恋的感觉 2021-01-29 11:18

I have a checkbox that confirms if the sender wants the copy of the form to his/her email. Now, how can I have get it to work with PHP?

I have the following HTML form cod

1条回答
  •  时光说笑
    2021-01-29 11:50

    First, check if the "sendcopy" checkbox is checked:

    $sendCopy = isset($_POST['sendcopy']);
    

    You don't have to check its value. The frontend simply won't send anything if the checkbox is not checked, so if it exists in the $_POST array, that means the user has checked it.

    Next, just send the exact same mail to the sender's email address:

            if ($sendCopy) {
                $sentToSender = mail($email, "=?$charset?B?" . base64_encode($subject) . "?=", $body, $head);
            }
    

    You can add this code just before redirecting your user to the success page.

    The missing parentheses have now been added to the code above, so it works well.

    0 讨论(0)
提交回复
热议问题