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

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')
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.