sending email in kohana - php

hi friends how to send a email through kohana 3.0
i tried but not working
my code is like this
$subject = ' : Message to Leet Street';
$from = array('Clarence', 'ratnaraju.java#gmail.com');
email::send('ratnaraju.bonam#gmail.com', $from , $subject, 'hi how r u Brother ');
url::redirect();
config file is:
return array
(
'default' => array(
'transport' => 'smtp',
'options' => array
(
'hostname' => 'smtp.gmail.com',
'username' => 'ratnaraju.bonam#gmail.com',
'password' => 'Ratna',
'port' => '465',
),
)
);
thanks in advance

Use this module to send email:
https://github.com/shadowhand/email
it needs this vendor in the vendor-dir:
https://github.com/swiftmailer/swiftmailer

Related

Cakephp 2.x email not working, Why this Error comes

I struck on this problem on many days. Please help. I have followed the cakephp documentation. but could not resolve issue.
Could not send email: unknown
Error: An Internal Error Has Occurred.
Following is Configuration emai.php
<?php
class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => 'developer.support#sevenrocks.in',
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
public $smtp = array(
'transport' => 'Smtp',
'from' => array('site#localhost' => 'SevenRocks'),
'host' => 'ssl://smtp.sevenrocks.in',
'port' => 465,
'timeout' => 30,
'username' => 'developer.support#sevenrocks.in',
'password' => 'developerofsevenrocks',
'client' => null,
'log' => true,
'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
}
Following is code in controller
$email = new CakeEmail();
$email->emailFormat('html');
$email->from(array($from_email => SITE_NAME));
$email->to($to);
$email->subject($subject);
if ($files)
{
$email->attachments($files);
}
if ( !$email->send($content) )
{
return false;
}
First: to debug CakePHP 2x applications search for debug in your app/Config/core.php and change it to Configure::write('debug', 2); to see the full error message.
Second: Some providers may prevent you from sending Mails via PHP directly (default mail config). A better solution may to use the smtp configuration you provided in email.php.
To use your smtp configuration change your controller code to:
$email = new CakeEmail('smtp');
$email->emailFormat('html');
$email->to($to);
$email->subject($subject);
For more Info see https://book.cakephp.org/2.0/en/core-utility-libraries/email.html#configuration

Not receiving emails fromCakeMail

I have a weird problem using CakePHP/CakeMail.
I try to send an email for my gmail from the website.
I don't get the email, but I don't get any error either.
The form send the message. The log don't hit anything. Passwords and emails are ok, so what could be wrong?
Here are the codes.
email.php
public $mymail = array(
'transport' => 'Smtp',
'from' => array('xpto#domain.com.br' => 'YourName'),
'sender' => 'my#gmail.com',
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'my#gmail.com',
'password' => 'mygmailpassword',
'client' => null,
'log' => true,
'emailFormat' => 'both'
'charset' => 'utf-8',
'returnPath' => 'xpto#domain.com.br',
'additionalParams' => '-f'.'xpto#domain.com.br',
'headerCharset' => 'utf-8',
);
PagesController.php
public function admin_send_contato() {
if ($this->request->is('post')) {
if(!isset($this->data['email'])){
$this->data['assunto'] = 'Assunto';
}
$email = new CakeEmail('mymail');
$this->Email->return = 'my#gmail.com';
$email->from(array('xpto#domain.com.br' => 'John Doe'))
->to('my#gmail.com')
->subject($this->data['subject'])
->replyTo($this->data['email'])
->send("Name: ".$this->request->data['name']."\nPhone: ".$this->request->data['phone']."\nE-mail: ".$this->request->data['email']."\nMessage: ".$this->request->data['message']);
echo json_encode('ok');
}
$this->autoRender = false;
}
I don't create the site and never used Cake before.
I have no idea what is the problem.
Any thoughts?
Thank you!
I'd recommend using a third party solution to send transactional and marketing emails. Sendgrid is an option and they have documentation to integrate in CakePHP; https://sendgrid.com/docs/Integrate/Frameworks/cakephp.html

sending email using zend/mail

I want to send an email using zend/mail in zend framework 2.
I already have some code but i don't know where to put it, and also not how to trigger this.
$mail = new Mail\Message();
$mail->setBody('This is the text of the email.');
$mail->setFrom('email#hotmail.be', 'email');
$mail->addTo('email#hotmail.be', 'email');
$mail->setSubject('Dit is een email verzonden van de computer');
$transport = new Mail\Transport\Sendmail('-freturn_to_email#hotmail.be');
$transport->send($mail);
I still new at Zend framework 2.
Can anybody help me with this?
I would advice you to take a look at Soflomo\Mail. Note, I am the author of Soflomo mail, but it helps you a lot with sending mails. It eases the config and dependency hassle.
Put "soflomo/mail": "~0.3" in your composer.json file and run the following command:
php composer.phar update soflomo/mail
Next, enable the module Soflomo\Mail in your application.config.php. When you use Zend\Mvc, you will have a controller/action which should trigger the email. For the most simplified use case, you can do this:
public function doAction()
{
// some of your logic
$service = $this->getServiceLocator()->get('Soflomo\Mail\Service\MailService');
$service->send(array(
'to' => 'email#hotmail.be',
'to_name' => 'email',
'from' => 'email#hotmail.be',
'from_name' => 'email',
'subject' => 'Dit is een email verzonden van de computer',
'template' => 'mail/message/default'
));
}
Now Soflomo\Mail sends a message by rendering a template and use that as message text. Here I defined a message mail/message/default so create that file (e.g. module/Application/view/mail/message/default.phtml) with this content:
This is the text of the email.
The last thing to do is to configure how Soflomo/Mail sends the message. Your question uses Sendmail, so I am using this as well in this example. Create a configuration file in config/autoload , e.g. config/autoload/soflomo_mail.global.php which contains the following content:
return array(
'soflomo_mail' => array(
'transport' => array(
'type' => 'sendmail',
),
),
);
If you want to switch to e.g. GMail as transport layer, replace above config with:
return array(
'soflomo_mail' => array(
'transport' => array(
'type' => 'smtp',
'options' => array(
'name' => 'gmail.com',
'host' => 'smtp.gmail.com',
'port' => 587,
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => '%USERNAME%',
'password' => '%PASSWORD%',
),
),
'variables' => array(
'username' => '',
'password' => '',
),
),
),
);
And create a new file config/autoload/soflomo_mail.local.php:
return array(
'soflomo_mail' => array(
'transport' => array(
'variables' => array(
'username' => 'my-address#gmail.com',
'password' => '1234secure7890',
),
),
),
);
I guess Hotmail would be similar to GMail.
You can use this within the zend directory,
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('somebody#example.com', 'Some Sender');
$mail->addTo('somebody_else#example.com', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send();

Swift Mailer with Decorator not sending mails in Yii2

I want to use the decorator to send custom messages to users.
For some reason, the same message gets send.
Why?
$replacements = array();
$replacements['f1#d.net'] = array(
'{v1}' => 'valoare1',
'{v2}' => 'valoare2',
);
$replacements['f2#d.net'] = array(
'{v1}' => 'valoare21',
'{v2}' => 'valoare22',
);
$replacements['f3#d.net'] = array(
'{v1}' => 'valoare31',
'{v2}' => 'valoare32',
);
$replacements['f4#d.net'] = array(
'{v1}' => 'valoare41',
'{v2}' => 'valoare42',
);
$replacements['f5#d.net'] = array(
'{v1}' => 'valoare51',
'{v2}' => 'valoare52',
);
echo count($replacements);
$decorator = new \Swift_Plugins_DecoratorPlugin($replacements);
$mailer = \Swift_Mailer::newInstance(
\Swift_SmtpTransport::newInstance('smtp', 25)
);
$mailer->registerPlugin($decorator);
$message = \Swift_Message::newInstance()->setSubject('title {v1}')->setBody('layout {v2}');
foreach ($replacements as $email => $replacement) {
$message->setFrom(array($email => 'to me'));
// $message->setTo($email);
$message->addTo($email);
$mailer->send($message);
}
Add following under your component in confi/main.php file.
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport'=>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'host_name',
'username' => 'user_name',
'password' => 'password',
'port' => '587',
'encryption' => 'tls'
],
]
And send mail using
\Yii::$app->mailer->compose()
->setHtmlBody("mail_content")
->setFrom('from_email_id')
->setTo('to_email_id')
->setSubject("Subject")
->send();

Create a simple SMTP module for Drupal

I want to write a simple Drupal7 module, which contains following codes, used to send mail. Don't ask me to use Phpmailer or others. Could you help? Thanks very much!
<?php
include('Mail.php');
$recipients = array( 'someone#example.com' ); # Can be one or more emails
$headers = array (
'From' => 'someone#example.com',
'To' => join(', ', $recipients),
'Subject' => 'Testing email from project web',
);
$body = "This was sent via php from project web!\n";
$mail_object =& Mail::factory('smtp',
array(
'host' => 'prwebmail',
'auth' => true,
'username' => 'YOUR_PROJECT_NAME',
'password' => 'PASSWORD', # As set on your project's config page
#'debug' => true, # uncomment to enable debugging
));
$mail_object->send($recipients, $headers, $body);

Categories