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.
Related
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");
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 :-)
This is my first application using Zend Framework 2. I want to send an email to recipients retreived from a database, but each time my code displays an error. This is my code:
$user = new Container('user');
$db = $this->getServiceLocator()->get('db1');
if (!$user->offsetExists('id')) {
$idconnected = '0';
} else {
$idconnected = $user->offsetGet('id');
$mail = $db->query("SELECT email FROM user WHERE id =" . $idconnected)->execute()->current();
$message = new Message();
$message->addTo($mail, 'eee#web.com')
->addFrom('xxxx#gmail.com')
->setSubject('Invitation à l’événement : Soirée Latino');
$message->addCc('xxxx#hotmail.com')
->addBcc("xxxx#hotmail.com");
// Setup SMTP transport using LOGIN authentication
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'host' => 'smtp.gmail.com',
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => 'xxxx#gmail.com',
'password' => '*********'
),
'port' => 587,
));
$html = new MimePart('<b>Invitation for the event: Latin Night, orgonized by Mr. Jony Cornillon <i>Date : 06/04/2015</i></b>');
$html->type = "text/html";
$body = new MimeMessage();
$body->addPart($html);
//$body->setParts(array($html));
$message->setBody($body);
$transport->setOptions($options);
$transport->send($message);
}
And this is the error:
5.1.2 We weren't able to find the recipient domain. Please check for any
5.1.2 spelling errors, and make sure you didn't enter any spaces, periods,
5.1.2 or other punctuation after the recipient's email address. a13sm19808164wjx.30 - gsmtp
I tried with this code, and now it works fine :
foreach ($mail as $recip) {
$message->addTo($recip);
$message->addTo('samehmay#hotmail.com', 'eee#web.com')
->addFrom('maysameh0#gmail.com')
->setSubject('Invitation à l’événement : Soirée Latino');
}
i get "Unknown email configuration 'gmail' " error , while trying to send an email using Cakephp ,is that because i'm sending it from localhost (xampp) ?
if($this->User->save($this->request->data)){
$message='Click on the link below to complete registration ';
$confirmation_link='www.sitename.com/users/verify/t:'.$hash.'/n:'.$this->data['User']['username'].'';
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('gmail');
$email->Email->from = 'myemail#gmail.com';
$email->Email->to=$this->data['User']['email'];
$email->Email->subject = 'Confirm Registration';
$email->Email->smtpOptions = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'myemail#gmail.com',
'password' => 'mypassword',
'transport' => 'Smtp'
);
$email->send($message . " " . $confirmation_link);
$this->Session->setFlash(__('you should activate your account'));
}
}
In order to use new CakeEmail('gmail') you have to config gmail in your configure file (/Config/email.php) such as:
public $gmail = [
'transport' => 'Mail',
'from' => 'you#localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
];
http://book.cakephp.org/2.0/en/core-utility-libraries/email.html
new CakeEmail('gmail') will read your gmail config and you will not have to configure it in your application.
If you do all your configuration in your application, perhaps you would like to use new CakeEmail();
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.)