9

Below is my code for sending mail and this is working fine but when i set cc or bcc mail is not sent them.

    $email = new EmailModel();
    $emailSettings = craft()->email->getSettings();

    $email->fromEmail = $emailSettings['emailAddress'];
    $email->replyTo   = $message->fromEmail;
    $email->sender    = $emailSettings['emailAddress'];
    $email->fromName  = $settings->prependSender . ($settings->prependSender && $message->fromName ? ' ' : '') . $message->fromName;
    $email->toEmail   = $toEmail;
    $email->cc   = explode(',', $message->fromEmail);
    $email->subject   = $settings->prependSubject . ($settings->prependSubject && $message->subject ? ' - ' : '') . $message->subject;
    $email->body      = $message->message;

    if ($message->attachment)
    {
        $email->addAttachment($message->attachment->getTempName(), $message->attachment->getName(), 'base64', $message->attachment->getType());
    }

    craft()->email->sendEmail($email);

please correct me where i wrong.

Thanks

Renish Khunt
  • 299
  • 1
  • 6

1 Answers1

9

The way you do it now only adds email addresses as an array. You'll have to specify both email and name keys too, so it becomes like this:

$email->cc = array(
    array('email' => 'email@email.com', 'name' => 'Name')
);
Brad Bell
  • 67,440
  • 6
  • 73
  • 143
Bob Olde Hampsink
  • 1,173
  • 7
  • 27