Question

I found a simple SMTPClient class for sending emails via SMTP. The problem is I need to add CC and BCC recipients to the client. Can someone assist in implementing this?

Heres the class (scroll down a little bit): SMTPClient

Thanks!

Was it helpful?

Solution

Have you actually read the same page you downloaded it from, one of the comments explains how to add CC and BCC to this, I obviously haven't tried this out myself, but have copied and pasted it for your reference here, changing some of the formatting to help:

1.First you need to change the file named index.php:

You have to add a new field called cc in your form. Then recover it to $cc from POST Array (within the other variables as $from, $to ...). Finally, you must add $cc between $to and $subject in the SMTPClient function call.

2. Next you have to change the file named SMTPClass.php:

You must add $cc to SMTPClient function definition the same way you did in the function call. Then add a new variable called $this->cc where you put the actual $cc.

Duplicate the RCPT TO command using your new variable $this->cc and get the response in the $talk[...] array:

 fputs ($SMTPIN, "RCPT TO: <".$this->cc.">\r\n");
 $talk["Cc"] = fgets ($SMTPIN, 1024); 

Finally, put your variable in the mail header, by adding the following line right after the "To:" line under DATA command:

Cc: <".$this->cc.">\r\n

The final DATA command is:

 fputs($SMTPIN, "DATA\r\n");
 $talk["data"]=fgets( $SMTPIN,1024 );
 fputs($SMTPIN, "To: <".$this->to.">\r\nCc: <".$this->cc.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
 $talk["send"]=fgets($SMTPIN,256);

You can do this the same way with BCc too...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top