drupal_mail and drupal_send_email don't work? - email

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.)

Related

Send email to all the rows from mysql in codeigniter

i need to send emails to all the rows in database table with their corresponsing data. i am able to send single emails by their id, but now i need to send in bulk. i have done in pure php but in codeigniter not able to figure out. how to do this.
my controller is
public function autoformcomplete()
{
$this->load->model('admin/Reminder_model');
$datan = $this->Reminder_model->autoformemail();
//this should be in whileloop, that i am not able to figure out
$email = $datan[0]['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->set_crlf("\r\n");
$subject = "Complete Your Partially Filled Application-".$appid."";
$data['datan'] = $datan;
$mesg = $this->load->view('email/reminder/form_complete',$data,true);
$this->email->to($email);
$this->email->from('mail#mail.com','My Company');
$this->email->subject($subject);
$this->email->message($mesg);
$this->email->send();
echo "sent";
}
My Model is
public function autoformemail(){
$this->db->order_by('id', 'DESC');
$query = $this->db->get('appstbldata');
return $query->result_array();
}
Just use a foreach loop
public function autoformcomplete() {
$this->load->model( 'admin/Reminder_model' );
$datan = $this->Reminder_model->autoformemail();
foreach ( $datan as $index => $val ) {
// $val now references the current pointer to an element in your $datan array
$email = $val['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize( $config );
$this->email->set_mailtype( "html" );
$this->email->set_newline( "\r\n" );
$this->email->set_crlf( "\r\n" );
$subject = "Complete Your Partially Filled Application-" . $appid . "";
$data['datan'] = $datan;
$mesg = $this->load->view( 'email/reminder/form_complete', $data, true );
$this->email->to( $email );
$this->email->from( 'mail#mail.com', 'My Company' );
$this->email->subject( $subject );
$this->email->message( $mesg );
$this->email->send();
echo "sent";
}
}
I dunno what your point of $data['datan'] = $datan; line is though

How can pass html special characters in smtp headers Array like QR code

This is my code i am sending Qrimage and also use br tag in message body ..but in email it showing me br tag and Qrimage not printing
$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $email_body);
You can pass it like this .It may Help you
$headers = array ('From' => $email_from, 'To' => $to, 'Subject' => $email_subject, 'Reply-To' => $email_address,'MIME-Version' => "1.0",'Content-type' => "text/html; charset=iso-8859-1\r\n\r\n");

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.

CAKE email not accepting variety of bcc/cc options

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.