PHP contact form coding help

Discussion in 'PHP' started by needhits.net, Jun 30, 2013.

  1. #1
    I want the script to send (cc) the message to EmailFrom also.

    Do I add to $EmailTo =

    What do I need to add?

    copy of form action script:
    
    // get posted data into local variables
    $EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
    $EmailTo = "[EMAIL]contact@emailmarketingclient.com[/EMAIL]";
    $Subject = "Free Account Setup";
    $Name = Trim(stripslashes($_POST['Name']));
     
    // validation
    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (Trim($Name)=="") $validationOK=false;
    if (!$validationOK) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.emailmarketingclient.com/error.html\">";
    exit;
    }
     
    // prepare email body text
    $Body = "";
    $Body .= "Client Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "\n";
    $Body .= "Client Email: ";
    $Body .= $EmailFrom;
    $Body .= "\n";
     
    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
     
    // redirect to success page
    if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=free-account-setup.php\">";
    }
    else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=free-account-setup.php\">";
    }
    
    PHP:
    Thanks
    Dave
     
    Last edited by a moderator: Jun 30, 2013
    needhits.net, Jun 30, 2013 IP
  2. langtusitinh225

    langtusitinh225 Greenhorn

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    Try it
    
    $EmailTo="contact@emailmarketingclient.com, secondmail@xxx.com";
    
    PHP:
     
    langtusitinh225, Jun 30, 2013 IP
  3. hangbowl

    hangbowl Well-Known Member

    Messages:
    228
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    143
    Digital Goods:
    2
    #3
    Try this,

    // get posted data into local variables
    $EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
    $EmailTo = "[EMAIL]contact@emailmarketingclient.com[/EMAIL]";
    $Subject = "Free Account Setup";
    $Name = Trim(stripslashes($_POST['Name']));
     
    // validation
    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (Trim($Name)=="") $validationOK=false;
    if (!$validationOK) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.emailmarketingclient.com/error.html\">";
    exit;
    }
     
    // prepare email body text
    $Body = "";
    $Body .= "Client Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "\n";
    $Body .= "Client Email: ";
    $Body .= $EmailFrom;
    $Body .= "\n";
     
    // headers
    $Header = "";
    $Header .= 'From: <$EmailFrom>' . "\r\n";
    $Header .= 'Cc: cc@example.com' . "\r\n";
    $Header .= 'Bcc: bcc@example.com' . "\r\n";
     
    // send email
    $success = mail($EmailTo, $Subject, $Body, $Header);
     
    // redirect to success page
    if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=free-account-setup.php\">";
    }
    else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=free-account-setup.php\">";
    }
    
    PHP:
     
    hangbowl, Jun 30, 2013 IP
  4. needhits.net

    needhits.net Member

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #4
    Problem is I dont know the second email until the person completes the for. The is the variable

    $EmailFrom= 
    Code (markup):
    is the person completing the form.


    I thought is would be something like:

    $EmailTo = "contact@emailmarketingclient.com,Trim(stripslashes($_POST['EmailFrom']))";
    Code (markup):

    But that didn't work.
    The listed ones above are not working also.
     
    needhits.net, Jul 6, 2013 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,897
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #5
    you can put variables inside strings but not functions. Try this

    $EmailTo = "contact@emailmarketingclient.com,".trim(stripslashes($_POST['EmailFrom']));
    PHP:
     
    sarahk, Jul 7, 2013 IP
  6. hangbowl

    hangbowl Well-Known Member

    Messages:
    228
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    143
    Digital Goods:
    2
    #6
    Ah, You said CC. Not direct mail. Just add it at the $header section, see this :
    $Header .= 'Cc: cc@example.com,'.trim(stripslashes($_POST['EmailFrom'])) . "\r\n";
    Code (markup):
     
    hangbowl, Jul 7, 2013 IP