indiodoido Posted May 12, 2009 Share Posted May 12, 2009 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? Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 12, 2009 Share Posted May 12, 2009 clue. $to = 'blabla@bla.com,another@who_ever.com'; Quote Link to comment Share on other sites More sharing options...
Adam Posted May 12, 2009 Share Posted May 12, 2009 EDIT: Redarrow's onto it! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 Php variables are not parsed when inside single-quotes. Your BCC header needs to use double-quotes so that the $bcc variable will be parsed and replaced with its contents. Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 12, 2009 Share Posted May 12, 2009 agree but was a clue only....... Quote Link to comment Share on other sites More sharing options...
Adam Posted May 12, 2009 Share Posted May 12, 2009 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? Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 12, 2009 Author Share Posted May 12, 2009 hey guy's! thanks for the reply's I added double-quotes to the bcc header: $headers .= "Bcc: $bcc" . "\r\n"; But it didn't work Quote Link to comment Share on other sites More sharing options...
Adam Posted May 12, 2009 Share Posted May 12, 2009 $to = 'blabla@bla.com,another@who_ever.com'; $to = 'blabla@bla.com, another@who_ever.com'; Perhaps? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 Define: didn't work? Is it sending to the To: address but not to any or just some of the Bcc: addresses? Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 12, 2009 Author Share Posted May 12, 2009 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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 Add the following two lines immediately after your first opening <?php tag to find out why the mail() function call is failing - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 12, 2009 Author Share Posted May 12, 2009 didn't display any php error's, only the my default mail failure: oh damm! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 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. Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 12, 2009 Author Share Posted May 12, 2009 i commented the Bcc header: //$headers .= "Bcc: $bcc" . "\r\n"; added one more email in the 'to' string: $to = 'xxxx@gmail.com, xxxx@rld-i.com'; and the email was sent to both addresses :S i'm going crazy with this! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 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. Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 12, 2009 Author Share Posted May 12, 2009 I sent a email do my hosting provider and brought up this issue. I hope they can help. By the way...is there any option in php.ini that can disable the use of the Bcc option in mail()? Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 13, 2009 Author Share Posted May 13, 2009 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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 13, 2009 Share Posted May 13, 2009 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. Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 13, 2009 Author Share Posted May 13, 2009 I'm not familiar to phpmailer class :S How do i work with it? Which is better, phpmailer ou SMTP? Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 13, 2009 Author Share Posted May 13, 2009 found a tutorial on how to work with PHPMailer 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? Quote Link to comment Share on other sites More sharing options...
Adam Posted May 13, 2009 Share Posted May 13, 2009 But even so i'm now getting the Bcc to work... :@ What do you mean by this? If it's not working, what error are you getting? What is actually happening? Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 13, 2009 Author Share Posted May 13, 2009 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() Quote Link to comment Share on other sites More sharing options...
Adam Posted May 13, 2009 Share Posted May 13, 2009 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); } Quote Link to comment Share on other sites More sharing options...
indiodoido Posted May 13, 2009 Author Share Posted May 13, 2009 thanks MrAdam! if only i had seen your post earlier lol I've managed to do something like you did, but more complicated... The important thing is that it's finally working Thanks allot to all who posted! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.