dimanche 17 avril 2016

PHPmailer: allow copy of email to be sent to sender if they check a box

I want users to be able to select a box that says "Send me a copy of the email" after completing a form. I'm using phpMailer to send the form to myself, and I don't know how to add a second email address under the condition that the person selected this box. Right now I have:

if (isset($_POST["send"]))
    {
        $senderEmail = $email;
    }   

and

<li>
<h4>Send me a copy of this form</h4>
<input type="radio" id="send" name="send" <?php if (isset($_POST["send"])) { echo "checked"; }?>>
<label for="send">Yes please</label>

<input type="radio" id="nosend" name="nosend" <?php if (isset($_POST["nosend"])) { echo "checked"; } ?>>
<label for="nosend">No, thank you</label>
</li>

and finally

{

        include("includes/class.phpmailer.php");
        $mail = new PHPMailer;

        $mail->setFrom($email, $firstname);
        $mail->addAddress('alexandra-lynn@hotmail.com'); 
        $mail->addAddress($senderEmail);
        $mail->addReplyTo($email, $name);
        $mail->isHTML(true);
        $mail->Subject = 'New email from ' . $name;
        $mail->Body    = "

        <h2>Email from your Website</h2>
        <p>Name: $firstname $lastname </p>
        <p>Email: $email </p>
        <p>Phone: $phone </p>
        <p>Country: $
        <p>Message: $comments </p>


        ";

Also, while we're looking at it, in the Body of the email as listed above, I want to get the information for Country which is in a dropdown selection menu. If anyone can also tell me how to do this, as well as how to do the same from whichever selection a sender makes from a radio checklist, I'd be very grateful.

Aucun commentaire:

Enregistrer un commentaire