CAKE email not accepting variety of bcc/cc options - email

I have tried many cake options to include a cc or bcc or additional email with the invoices and nothing works, I need a a workable example to the following format, I have have not found any clear solution.
public function send() {
$id = $this->request->data['Invoice']['id'];
$invoiceNumber = $this->request->data['Invoice']['invoice_number'];
$to = $this->request->data['Invoice']['to'];
$from = $this->request->data['Invoice']['from'];
$message = $this->request->data['Invoice']['message'];
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail();
$email->config(array(
'from' => $from,
'transport' => 'Mail',
'charset' => 'utf-8',
'headerCharset' => 'utf-8'
));
$result = $email->emailFormat('html')
->to($to)
->addbcc('WCMBilling#icloud.com')
->from($from)
->returnPath($from)
->subject('New Invoice ('.$invoiceNumber.')')
->attachments(WWW_ROOT.'/temp/Invoice_'.$invoiceNumber.'.pdf')
->send($message);
unlink(WWW_ROOT.'/temp/Invoice_'.$invoiceNumber.'.pdf');
$this->Session->setFlash('Email Sent');
$this->redirect(array('controller'=>'invoices', 'action'=>'view', $id));
}

I found it in the email.php file.
Where there is "null" on the cc line, or bcc line, enter the desired email and all works fine.

Related

How to set multiple CC email recipients one message using webform in drupal 7

My website using webform in drupal 7 application.
I have two queries
I can added a list for To email recipients one message. Email will receiving all the recipients but mails sending individual. I cant see in the to list group.
How to set multiple CC email recipients one message ? Here am using 'CC' => 'xx#yyyy.com, xx1#yyyy1.com, xx2#yyyy2.com' in theme_mail_headers under "$headers.
function MODULENAME_mail($key, &$message, $params) {
if($key === 'MODULEcase') {
$header = array(
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal',
'Cc' => implode(',', $params['Cc']),
);
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
foreach ($headers as $key => $value) {
$message['headers'][$key] = $value;
}
break;
}
}
Then prepare data and pass to drupal_mail function
$mail_content = "Hello There!";
$params = array('body' => $mail_content);
$params['cc'] = array(
'cc_user1#example.com',
'cc_user2#example.com',
'cc_user3#example.com',
);
$to = 'touser#example.com';
$from = 'no-reply#example.com';
$mail = drupal_mail('MODULENAME', 'MODULEcase', $to, language_default(), $params, $from);
This is it. Enjoy :-)

HTML email through SES SMTP interface - PEAR

I wish to send HTML emails. I tried using mime.php but could not get it working. Below is my working text email code:
<?php
$subject="hello-test";
$body="<html><body><h1>message body</h1></body></html>";
$em_arr=array("email#example.com");
foreach ($em_arr as $to_address)
{
require_once '/usr/local/share/pear/Mail.php';
$headers = array (
'Content-Type:text/html;charset=UTF-8',
'From' => 'Test <test#example.com>',
'To' => $to_address,
'Subject' => $subject);
$smtpParams = array (
'host' => '<smtp host address>',
'port' => 587,
'auth' => true,
'username' => '<uname>',
'password' => '<password>'
);
// Create an SMTP client.
$mail = Mail::factory('smtp', $smtpParams);
// Send the email.
$result = $mail->send($to_address, $headers, $body);
if (PEAR::isError($result)) {
echo("Email not sent. " .$result->getMessage() ."\n");
} else {
echo("Email sent to ".$to_address."\n");
}
}
?>
Please let me know how can I send HTML emails.
I had to replace the Content header line to:
'Content-Type' => "text/html; charset=UTF-8",
That was the mistake above. It is working fine now.

MIME::Lite - Mail to multiple recipients [duplicate]

Please find below my code snippet that send a mail to person and his friend in cc.
In the cc list I also have a DL.
use MIME::Lite;
$to = 'ABC#DOMAIN1.com';
$from = 'MAILER#DOMAIN2.com';
$subject = 'How are you doing';
$message = 'This is test email sent by Perl Script';
my #cc=('XYZ#DOMAIN2.com','DL#DOMAIN2.com');
$msg = MIME::Lite->new(
From => $from,
To => $to,
Cc =>\#cc,
Subject => $subject,
Data => $message
);
$msg->send('smtp','smtpserver', Timeout => 60 );
print "Email Sent Successfully\n";
The problem is the person and DL is cc are not receiving the mails.
Is there any log in the api MIME::Lite where I can check what is the error(if any)Or what do you think the problem can be?
Perhaps you want to take a closer look at the documentation for MIME::Lite. Here's the first example from the synopsis.
use MIME::Lite;
### Create a new single-part message, to send a GIF file:
$msg = MIME::Lite->new(
From => 'me#myhost.com',
To => 'you#yourhost.com',
Cc => 'some#other.com, some#more.com',
Subject => 'Helloooooo, nurse!',
Type => 'image/gif',
Encoding => 'base64',
Path => 'hellonurse.gif'
);
$msg->send; # send via default
The Cc parameter here is sent as a text string containing comma-separated email addresses. You are passing in a reference to an array of email addresses.

drupal_mail and drupal_send_email don't work?

My situation is as follows:
I use ubercart and I have 3 modules installed for email (when a customer makes the purchase) confirmation of a purchase. The modules are: SMTP, MIMEMail and HTML MAIL.
Verifying, sending works with HTML.
However, I need to make another type of email, when a product expires.
And that I'm doing with my own module. However, when I use the function of drupal_mail or drupal_mail_send sending doesn't correct.
When I debug the function apparently everything is correct, but I don't get any email.
My code for the function is drupal_mail_send:
$message = array(
'to' => $to,
'from' => $from,
'id' => 'cuponalcubo_mailing',
'subject' => $subject,
'body' => $body,
'headers' => array(
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Pressflow',
)
);
drupal_mail_send($message);
And the code for the function is drupal_mail:
function ....(){
$params = array(
'subject' => $subject,
'body' => t($body)
);
drupal_mail('email_deal_vp', 'email_deal_vp_html_mail', $to, language_default(), $params, $from);
}
/*
* Implements HOOK_MAIL
*/
function email_deal_vp_mail($key, &$message, $params) {
$language = $message['language'];
switch ($key) {
case 'email_deal_vp_html_mail':
$message['subject'] = t($params['subject'], $var, $language->language);
$body = "<html><body>
{$params['body']}
</body></html>";
$message['body'][] = $body;
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
break;
}
}
Maybe this is a problem with your server (SMTP is not configured properly). Check with any existing mail code whether it is working. (If it was working before.)

Email does not send with perl MIME::Lite using smtp

I am trying to send an email using MIME::Lite but the email will not send and I am not getting any errors.
Code:
my $subject = $Config->{email}->{subject};
my $from_email = $Config->{email}->{from_email};
my $message = $Config->{email}->{message};
my $smtp_server = $Config->{email}->{smtp_server};
my $msg = MIME::Lite->new
(
Subject => $subject,
From => $from_email,
To => $email,
Type => 'text/html',
Data => $message
);
$msg->send('smtp' ,$smtp_server );
Not much to go on there ...
Maybe try debugging?
$msg->send( 'smtp', $smtp_server, Debug=>1 );
And check all the values in $Config->{email} are as you would expect.