Problem sending website form to bcc email with php

Discussion in 'PHP' started by creations121, Aug 24, 2009.

  1. #1
    I have been relentlessly trying to get this done but have not achieved success.
    I have a website form which is processed by a php script and email is sent to me.
    I want this email to be sent to two different email ids and want one of them to be bcc.
    I have this on bluehost linux servers.
    I would be really very much obliged if someone can help me out with this.
    My changed code is as follows

    <?php
    $email = Trim(stripslashes($_POST['email']));
    $torecipient = "xxxww";
    $header = "From: $email\r\n";
    $header .= "Reply-to: $email\r\n";
    $header .= "bcc: xxxx\r\n";
    $txt1 = Trim(stripslashes($_POST['state']));
    $txt2 = "State,Contact Form";
    $Subject = $txt1 . " " . $txt2;
    $company = Trim(stripslashes($_POST['company']));
    $address = Trim(stripslashes($_POST['address']));
    $country = Trim(stripslashes($_POST['country']));
    $state = Trim(stripslashes($_POST['state']));
    $zip = Trim(stripslashes($_POST['zip']));
    $contactno = Trim(stripslashes($_POST['contactno']));
    $person = Trim(stripslashes($_POST['person']));
    $email = Trim(stripslashes($_POST['email']));
    $box1 = Trim(stripslashes($_POST['box1']));
    $box2 = Trim(stripslashes($_POST['box2']));
    $box3 = Trim(stripslashes($_POST['box3']));
    $box4 = Trim(stripslashes($_POST['box4']));
    $other = Trim(stripslashes($_POST['other']));
    $comment = Trim(stripslashes($_POST['comment']));

    $Body = "";
    $Body .= "Company: ";
    $Body .= $company;
    $Body .= "\n";
    $Body .= "Address: ";
    $Body .= $address;
    $Body .= "\n";
    $Body .= "Country: ";
    $Body .= $country;
    $Body .= "\n";
    $Body .= "State: ";
    $Body .= $state;
    $Body .= "\n";
    $Body .= "Zip Code: ";
    $Body .= $zip;
    $Body .= "\n";
    $Body .= "Contact No: ";
    $Body .= $contactno;
    $Body .= "\n";
    $Body .= "Contact Person: ";
    $Body .= $person;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $email;
    $Body .= "\n";
    $Body .= "Mega: ";
    $Body .= $box1;
    $Body .= "\n";
    $Body .= "HyPer: ";
    $Body .= $box2;
    $Body .= "\n";
    $Body .= "Washer: ";
    $Body .= $box3;
    $Body .= "\n";
    $Body .= "Other: ";
    $Body .= $box4;
    $Body .= "\n";
    $Body .= "Other: ";
    $Body .= $other;
    $Body .= "\n";
    $Body .= "Comments: ";
    $Body .= $comment;
    ini_set ("sendmail_from","<$email>");
    // send email
    mail($torecipient, $Subject, $Body, $header);
    // redirect to success page
    if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=\">";
    }
    else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=\">";
    }
    ?>



    Please help me out with this.
    I am receiving the email to both email addresses but not as bcc.Both email ids are visible in the to header section of the email

    Please help :confused:
     
    Last edited: Aug 24, 2009
    creations121, Aug 24, 2009 IP
  2. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #2
    I think it should be
    
    $header .= "Bcc: xxxx\r\n";
    
    PHP:
    No space bet ween quote and Bcc
    also I think \r\n is right rather than \n
     
    prasanthmj, Aug 24, 2009 IP
  3. creations121

    creations121 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have made those changes as well,but no success
     
    creations121, Aug 25, 2009 IP
  4. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #4
    try changing "From: $email" to "From:name@websitename.com " where websitename.com is the name of the website where this script is running.

    From address from the originating server is required for some email receivers.
     
    prasanthmj, Aug 25, 2009 IP
  5. creations121

    creations121 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have even tried doing this
    No success#######
     
    creations121, Aug 25, 2009 IP
  6. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I don't see any issues perse, but it's probably better to use a mail library instead of the built in functionality. Use http://swiftmailer.org/
     
    premiumscripts, Aug 25, 2009 IP
  7. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    How do you like that compared to say PHPMailer?
     
    kblessinggr, Aug 25, 2009 IP
  8. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well, I actually switched to swiftmailer back in the day when it seemed like phpmailer development was stale. It seems that it is now in active development again, since I'm no longer using it I can't really give an honest comparison of the two. Swiftmailer does all I need and it has excellent documentation.
     
    premiumscripts, Aug 25, 2009 IP