PHP Email Help

  • Started
  • Last post
  • 9 Responses
  • ETM

    Hey. I have to add a BCC recipient to a PHP script done by someone else, but they employed a plain text method that I am not sure about (usually use the headers method). Anyone know what the syntax would be for a BCC? Google hasn't been helpful yet:

    //send the confirmation email
    if($msg == "update_success"){
    $sender =
    $from = "from:$sender";
    $email_date = date('M,d,Y', time());
    $recipient = $Name1Email;
    $subject = "Your Email Subject"
    $today = date ("l F d Y");

    BTW I am not a PHP developer. Can manage a few things, and am only doing this because it's a small task. :)

  • albums0

    $headers = 'Bcc: . "\r\n";

    • That would still work in this context? I'll try it out.ETM
  • ETM0

    No, in this case that is not working... anyone else have any thoughts?

  • vaxorcist0

    are you sending an HTML or plaintext email?
    are you sending an attachment?

    example code from the PHP manual page...

    // To send HTML mail, the Content-type header must be set
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    $headers .= 'To: Mary <>, Kelly < . "\r\n";
    $headers .= 'From: Birthday Reminder < . "\r\n";
    $headers .= 'Cc: . "\r\n";
    $headers .= 'Bcc: . "\r\n";

    // Mail it
    mail($to, $subject, $message, $headers);

    • oops, I see your original code, but I always use the headers method for bcc....vaxorcist
  • vaxorcist0

    It seems headers are the defined way.... various ways to code this... but it should be easy to convert the other code to "header-style" code, you can use arrays or concatenated strings....

    $headers = array();
    $headers[] = "MIME-Version: 1.0";
    $headers[] = "Content-type: text/plain; charset=iso-8859-1";
    $headers[] = "From: Sender Name <
    $headers[] = "Bcc: JJ Chong <
    $headers[] = "Reply-To: Recipient Name <
    $headers[] = "Subject: {$subject}";
    $headers[] = "X-Mailer: PHP/".phpversion();

    mail($to, $subject, $email, implode("\r\n", $headers));

    • without the ugly, vurnable \r\n hard-coded windows/unix return characters that are so problematic in above example...vaxorcist
  • vaxorcist0

    also, there are notes about tweeky string returns.. see:

    Be careful to not put extra spaces for the $headers variable.

    For example, this didn't work on our servers:

    $headers = "From: $from \r\n Bcc: $bcc \r\n";

    But this did:

    $headers = "From: $from\r\nBcc: $bcc\r\n";

    Notice the removal of the spaces around the first \r\n.

  • vaxorcist0

    also note that this is in the manual page notes...

    If you have Suhosin installed it will prevent mail() from sending CC and BCC emails.

    You can verify whether or not Suhosin is installed using the following code snippet:
    $phpinfo = ob_get_contents();
    $answer = 'No';
    if (strpos($phpinfo, "Suhosin") !== FALSE)
    $answer = 'Yes';
    echo $answer;

  • ETM0

    The headers method pointed out is what I am familiar with and maybe I'll just have to rewrite this bit. I have no idea what the original intention was. it works, but... well it stinks. I WAS hoping that maybe there was an elusive line or 2 of code I could add for the BCC in it's current state, but I guess not. And I can't find anyone on Google doing it quite this way either.

    Cheers for the input @albums and @vaxorcist!

  • vaxorcist0

    You probably already know this, but PHP forms tend to be spam vurnable, and if you're inheriting some untested code, I'd at least check things like……

    • Thanks. It's not a form (luckily). It's just sends out a system email notice after an update action.ETM
  • i_was0

    i dont understand the question, php mail is php mail function. what else?

    • insert georges clooney nespresso picturei_was
    • There are numerous ways to skin a cat...ETM
    • Besides the thread is done.ETM