0

I've got this little bump... I'm trying to send bcc copies but when I increase the number of headers the attached files are sent as the images code.

Here is my code:

    $to="name@extension.com";
    $subject="Petición de financiamiento";
    $from = stripslashes($_POST['nombre'])."<".stripslashes($_POST['correo']).">";
    $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
    $headers = "From: $from\r\n" .
    "MIME-Version: 1.0\r\n" .
    "Content-Type: multipart/mixed;\r\n" .
    " boundary=\"{$mime_boundary}\"";
    $message="Petición de financiamiento\r\n";
    $message .="\r\n";
    $message .= "Nombre: ".$_POST["nombre"]."\r\n";
    $message .= "Correo: ".$_POST["correo"]."\r\n";
    $message .= "Teléfono: ".$_POST["telef"]."\r\n";
    $message .="\r\n";
    $message .="\r\n";
    $message .= $_POST["mensaje"];
    $message .="\r\n";
    $message .="\r\n";
    $message = "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary}\n" .
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $message . "\n\n";
    foreach($_FILES as $userfile){
    $tmp_name = $userfile['tmp_name'];
    $type = $userfile['type'];
    $name = $userfile['name'];
    $size = $userfile['size'];
    if (file_exists($tmp_name)){
    if(is_uploaded_file($tmp_name)){
      $file = fopen($tmp_name,'rb');
      $data = fread($file,filesize($tmp_name));
      fclose($file);
      $data = chunk_split(base64_encode($data));
    }
    $message .= "--{$mime_boundary}\n" .
      "Content-Type: {$type};\n" .
      " name=\"{$name}\"\n" .
      "Content-Disposition: attachment;\n" .
      " filename=\"{$fileatt_name}\"\n" .
      "Content-Transfer-Encoding: base64\n\n" .
    $data . "\n\n";
    }
    }
    $message.="--{$mime_boundary}--\n";
    $message.="--{$mime_boundary}--\n";
    if (@mail($to, $subject, $message, $headers))
    echo "Mensaje enviado";
    else
    echo "No se pudo enviar";

Any Idea how to add the BCC's, thank you in advance for any help.

Samuel Ramzan
  • 1,770
  • 1
  • 15
  • 24
  • If you have tried some of the answers below, and still have problems, it looks like your issue is not in specifying the bcc but in sending the attatchments. Take a look at http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail and consider switching to PHPMailer. – MarcM Apr 05 '16 at 13:17

4 Answers4

0

Just put $headers .= "Bcc: $emailadress\r\n"; say after the Content-type line

that should work i guess.

0
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";

On your headers just add this line

$headers.= "Bcc: email@example.com" . "\r\n";

Check the php mail function http://php.net/manual/en/function.mail.php

vinay rajan
  • 351
  • 4
  • 9
0

[Edited to fit the 'real' solution Sam Ram San have found by himself]

A nice, clear and expandable way to manage headers (including bcc):

$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: $from";
$headers[] = "Bcc: $bcc_address1,$bcc_address2,$bcc_address3";
// and so on...

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

Using this you avoid including unwanted blank spaces in front of the header field names ("Bcc" -> correct. " Bcc" -> incorrect)

Edited: as a general rule when sending emails, multiple addresses (in from, cc, bcc, cco... fields) should be separated using commas sign (","). I.e: $bcc="john@doe.com,james@doe.org,lucy@doe.com"

MarcM
  • 2,173
  • 22
  • 32
0

All I needed to do was to use a csv on the:

$to="name@extension.com,mail2@bla.com";

Thank You guys.

Samuel Ramzan
  • 1,770
  • 1
  • 15
  • 24