Jump to content

[SOLVED] Bcc Mail


indiodoido

Recommended Posts

hi!

 

I'm trying to send a email to multiple addresses using Bcc. Ok...seems simple, but the truth is that i'm not getting it to work :(

 

Here's my code:

$mails[1] = "test1@teste.com";
$mails[2] = "test2@teste.com";
$mails[3] = "test3@teste.com";
$mails[4] = "test4@teste.com";

$bcc = implode(",", $mails);

$to      = 'blabla@bla.com';
$subject = 'Email test';
$message = 'Welcome!';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: Test Site <test@test.com>' . "\r\n";
$headers .= 'Bcc: $bcc' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();

if( mail($to, $subject, $message, $headers) )
{
echo "oh eya!";
}
else
{
echo "oh damm!";
}

 

I have a simple function to check which emails were submitted by the user and store them in a array. This way there won't be any empty emails.

 

 

Can anyone tell me why this isn't working?

 

Link to comment
Share on other sites

I went to grab a coffee in between replying and didn't see your reply at first, but I was going with that there weren't spaces between the email address? I'm not sure how tight PHP is with this?

Link to comment
Share on other sites

It gives me the "oh damm!" warning. In other words the mail() function didn't send the email :S

Anyway i checked to see if the emails were send, but neither the to: email or the bcc: emails where delivered

 

tried this too, and didn't work :S

$to      = 'blabla@bla.com,another@who_ever.com';

$to      = 'blabla@bla.com, another@who_ever.com';

 

Perhaps?

Link to comment
Share on other sites

Either your web host has disabled the mail() function (can you send an email at all using just a To: address) or your web host has configured the mail server to hide errors so that mail server information is not exposed by people deliberately probing the mail server. In either case you probably need to contact your host to find out the requirements for what you are attempting.

Link to comment
Share on other sites

Your web host has probably disabled the use of Bcc:. Why don't you contact then to find out one way or the other. They may have a limit on the total number of destination addresses in a single call to the mail function. Find out, ask them what the requirements or restrictions are.

Link to comment
Share on other sites

I've contacted my hosting administrator and i've found out that they disabled Cc and Bcc headers in php mail() with Suhosin :(

 

Now lets i'm waiting to see if they are going to enable that option so that i can use Bcc in my project.

 

Just one question...if they don't enable that feature, is were any other way to send emails to multiple addresses without the other users seeing the emails?

Link to comment
Share on other sites

Just use the phpmailer class to interface directly with your sending mail server. The phpmailer can be configured to use sendmail (on UNIX/LINUX servers), mail(), or SMTP to interface with the mail server. Just use either the sendmail or SMTP options.

Link to comment
Share on other sites

found a tutorial on how to work with PHPMailer :D

 

But even so i'm now getting the Bcc to work... :@

 

Here's my code:

require_once('url/PHPMailer/class.phpmailer.php');

$mail = new PHPMailer();

$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "blabla"; // SMTP username
$mail->Password = "blabla"; // SMTP password

$mail->From = "from@hotmail.com";
$mail->FromName = "fromName";
//$mail->AddAddress("sendto@gmail.com","sendto");
//$mail->AddReplyTo("from@hotmail.com", "from");
$mail->AddBCC("$bcc"); //bcc has the list of addresses

$mail->IsHTML(true);
$mail->Subject = "Online";
$mail->Body = "bla bla bla bla bla...";
$mail->WordWrap = 50;

if(!$mail->Send())
{
   echo "Message was not sent";
   echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
  echo "mail sent!";
}

 

What i'm i doing wrong now?

Link to comment
Share on other sites

I found the problem...

 

I has trying to fill the Bcc field like this:

$mail->AddBCC("email1@hotmail.com, email2@hotmail.com, email3@hotmail.com");

 

and it seems that's not correct :s

if i have to send the email to multiple addresses using Bcc, i have to do this:

$mail->AddBCC("email1@hotmail.com");
$mail->AddBCC("email2@hotmail.com");
$mail->AddBCC("email3@hotmail.com");

 

i've managed to send the email to some teste addresses and it worked this way...but now i have a big problem, i wanted to fill the Bcc field with email addresses dynamically, just like i was doing in the first post using mail() :(

Link to comment
Share on other sites

Ahh!

 

If you have a pretty large amount of emails in an array like in your original code, you could use:

 

$mails[1] = "test1@teste.com";
$mails[2] = "test2@teste.com";
$mails[3] = "test3@teste.com";
$mails[4] = "test4@teste.com";

foreach ($mails as $email)
{
    $mail->AddBCC($email);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.