Page 1 of 1

EMAIL(Bcc) - URGENT

Posted: Thu Sep 14, 2006 8:48 am
by madhu
Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Dear All,

am trying to send mails as BCC.

[u][b]CODE[/b][/u]

Here first after submitting am requseting all the variables to send mail.

****************************************************************************************

Code: Select all

if(isset($_REQUEST['subject']) && isset($_REQUEST['admin']) && isset($_REQUEST['useremail']) && isset($_REQUEST['message']))
 {
 if(isset($_REQUEST['subject'])) $subject=$_REQUEST['subject'];               //Subject
 if(isset($_REQUEST['admin'])) $admin=$_REQUEST['admin'];                    //From - Mail Id
 if(isset($_REQUEST['useremail'])) $useremail=$_REQUEST['useremail'];   //To - Mail Id
 if(isset($_REQUEST['message'])) $message=$_REQUEST['message'];     //Message
 foreach($useremails as $user_email)
 {
   $user_email="".$user_email."".",";
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 $headers .= 'Bcc: $user_email' . "\r\n";                                                   //Bcc
   if(mail($useremail, $subject, $message, $headers))
     {
       echo "<html><body>";
       print "<script language=\"javascript\" type=\"text/javascript\">";
       print "window.close();";
       print "</script>";
       echo ("</body></html>");
   }
  }
}
**************************************************************************************

Now problem is am sending mail to "To Mail Id i.e first variable of mail()".

But mail is not going to Bcc(mail id's).

It is coming only to "To Mail Id i.e first variable of mail()".

I think am clear with my problem.

Waiting for your valuable replies to implement this issue.

Thanks and Regards
MADHU

Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Sep 14, 2006 8:50 am
by madhu
in this this variable $useremails contains array of mail id's which i want to send as Bcc.

Posted: Thu Sep 14, 2006 11:38 am
by John Cartwright
you had a couple things wrong with your code and logic..

like your loop was in the wrong spot -- according to your code you wanted to open a new mail connection per email. I've corrected it to only send one mail() and use bcc for the rest of the emails.

Secondly, you might want to avoid the use of $_REQUEST. You should always be specific of where your data comes from. I assume you've set your form method to POST, so use the $_POST superglobal.

Also, you might want to double check your sending all the appropriate headers. These headers will likely be flagged as spam by most email providers.

Do a search for Swift mailer on our forums, or even PHPmailer. Lastly, if your sending a lot of emails you should look into SMTP mailing.

Code: Select all

if(isset($_POST['subject']) && isset($_POST['admin']) && isset($_POST['useremail']) && isset($_POST['message']))
	{
		$subject = $_POST['subject'];     //Subject
		$admin = $_POST['admin'];         //From - Mail Id
		$useremail = $_POST['useremail']; //To - Mail Id
		$message = $_POST['message'];     //Message
		
		$headers = "From: mailer@mydomain.com\r\n";
		$headers .= "Reply-to: noreply@mydomain.com\r\n";
		
		foreach($useremails as $user_email)
		{
			$headers .= 'Bcc: $user_email' . "\r\n";	 //Bcc
		}

		$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";		

		if(mail($useremail, $subject, $message, $headers))
		{
			echo "<html><body>";
			print "<script language=\"javascript\" type=\"text/javascript\">";
			print "window.close();";
			print "</script>";
			echo ("</body></html>");
		}
	}

Posted: Thu Sep 14, 2006 11:57 am
by ok
I recommend you to use Swift or PHPMailer.