Grow your CSS skills. Land your dream job.

One submit button, two recipients

  • # May 4, 2009 at 4:32 pm

    Hi all -

    I took the simpleform from the site and have modified it a bit to allow the user to choose who receives the email.
    I also wanted to add a ‘CC’ if possible.

    Here is the code:

    Code:
    < ?php

    $EmailFrom = Trim(stripslashes($_POST['Email']));
    $EmailTo = Trim(stripslashes($_POST['Recipient']));
    $EmailCc = "MYEMAIL@gmail.com";
    $Subject = "TEST Contact";
    $Name = Trim(stripslashes($_POST['Name']));
    $Tel = Trim(stripslashes($_POST['Tel']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Message = Trim(stripslashes($_POST['Message']));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print "“;
    exit;
    }

    // prepare email body text
    $Body = “”;
    $Body .= “Name: “;
    $Body .= $Name;
    $Body .= “n”;
    $Body .= “Tel: “;
    $Body .= $Tel;
    $Body .= “n”;
    $Body .= “Email: “;
    $Body .= $Email;
    $Body .= “n”;
    $Body .= “Message: “;
    $Body .= $Message;
    $Body .= “n”;

    // send email
    $success = mail($EmailTo, $Subject, $Body, “From: < $EmailFrom>“);

    // redirect to success page
    if ($success){
    print ““;
    }
    else{
    print ““;
    }
    ?>

    I added this little snippet as i thought it may send the second email, but it didn’t work.

    Code:
    $EmailCc = “MYEMAIL@gmail.com”;

    Maybe I should just modify the ‘$EmailTo’ variable, but i’m not too proficient in php.

    # May 4, 2009 at 5:40 pm
    Code:
    $EmailTo = “UREMAIL@EMAIL.COM, “.Trim(stripslashes($_POST[‘Recipient’]));
    # May 13, 2009 at 2:56 pm

    if you want to carbon copy just do this:

    Code:
    $success = mail($EmailTo, $Subject, $Body, “From: < $EmailFrom>“);

    // redirect to success page
    if ($success){
    //copy to someone else
    mail(newaddress@newaddress.com, $Subject, $Body, “From: < $EmailFrom>“);
    print ““;
    }

    # May 13, 2009 at 3:15 pm

    All you need to do is pass the CC in the last variable of mail();

    Code:
    < ?php

    $header = "From: $EmailFromrn";
    $header .= "CC: otheremail@*website*.comrn";
    $header .= "BCC: yetanotheremail@*website*.comrn";

    // send email
    $success = mail($EmailTo, $Subject, $Body, $header);

    ?>

    Enjoy,

    # May 13, 2009 at 3:17 pm

    Sorry about the double post, but I forgot to mention.

    It’s good practice to always send the email from the domain that your server is on and use a replyto instead.

    Code:
    < ?php

    $header = "From: server@thisdomain.comrn";
    $header .= "Replyto: $EmailFromrn";

    $header .= "CC: otheremail@*website*.comrn";
    $header .= "BCC: yetanotheremail@*website*.comrn";

    // send email
    $success = mail($EmailTo, $Subject, $Body, $header);

    ?>

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".