Send e-mail from outlook using PHP,, CC and BCC problem -Not about PHPMailer

Viewed 65

i am trying to send e mail via outlook by php. i succeed this with this code, but i couldnt find how to add CC and BCC recipients.

$subject="Hi from your city"
$message= "hello my darling";

$to="example@gmail.com";
// starting outlook        
com_load_typelib("outlook.application"); 

if (!defined("olMailItem")) {define("olMailItem",0);}

$outlook_Obj = new COM("outlook.application") or die("Unable to start Outlook");

//just to check you are connected.        
echo "Loaded MS Outlook, version {$outlook_Obj->Version}\n";        
$oMsg = $outlook_Obj->CreateItem(olMailItem);  

$oMsg->Recipients->Add($to);

$oMsg->Subject=$subject;        
$oMsg->Body=$message;        
$oMsg->Save();        
$oMsg->Send();   
1 Answers

You can use the Recipients.Add method which creates a new recipient in the Recipients collection. Then you can set the Type property which represents the type of recipient. A raw sketch in C#:

recipientBCC = recipients.Add("eugene.astafiev@somedomain.com");
recipientBCC.Type = (int)Outlook.OlMailRecipientType.olBCC;

Read more about that in the How To: Fill TO,CC and BCC fields in Outlook programmatically article.


Also keep in mind that Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

See Considerations for server-side Automation of Office for more information on that.

Related