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
Related
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
I am looking a site. I'm new in this site and I don't know CakePhp. This site has users and I try do a forgot password page. I searched but can't a way or missed that.
UsersController.php
...
if ($this->User->save($this->data)) {
App::uses('CakeEmail', 'Network/Email');
$settings = $this->requestAction('pages/setting');
$this->email = new CakeEmail('smtp');
$email = $select['User']['email'];
$content = sprintf('<body> Sevgili ' . $select['User']['username'] . ", <br>
Şifre yenileme talebiniz tarafımıza iletilmiştir.
Aşağıdaki linki tıklayarak yeni şifrenizi belirleyebilirsiniz. <br>
Buraya Tıklayınız <br>
Keyifli Gezintiler <br>
Yukardaki link ile bağlantı sağlayamıyorsanız,
linki web tarayıcınızın adres bölümüne kopyalayabilirsiniz.</body>", $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], $code);
$this->email->from(array($settings['Setting']['smtp_mail'] => $settings['Setting']['title']))
->to($email)
->emailFormat('html')
->subject('Şifre Yenileme [' . time() . ']');
if ($this->email->send($content)) {
$this->Session->setFlash(__('Şifre güncelleme bilgileriniz E-Posta adresinize gönderilmiştir.'), 'default', array('class' => 'success'));
} else {
trigger_error("error Mail");
}
$this->redirect('forgot');
}
And Config/email.php
class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => 'you#localhost',
);
public $smtp = array(
'transport' => 'Smtp',
'from' => array('mymail#gmail.com' => 'Mysite'),
'host' => 'smtp.gmail.com',
'port' => 587,
'timeout' => 30,
'username' => 'mymail#gmail.com',
'password' => 'mypassword',
'client' => null,
'log' => true,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
'tls' => true
);
I say again: I'm new worker on this site and another worker used that codes. I don't know why that codes doesn't work now. And I asked that.Thanks a lot for all advices.
With the code below my emails would send fine in dev mode. Now that I've put my App into production mode when I try to trigger one of the actions to send an email the page just loads and loads until I get the CakePHP error. The data still goes into the database however.
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
'mailjet' => [
'host' => 'in-v3.mailjet.com',
'port' => 587,
'timeout' => 60,
'username' => 'removed',
'password' => 'removed',
'className' => 'Smtp'
],
],
public function register()
{
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->data);
$user->role = 'user';
$user->email_verified = '0';
$user->email_token = Security::hash($user->username + microtime(), 'sha1', true);
$user->email_token_expires = strtotime('now');
$user->email_token_expires = strtotime('+1 hour');
if ($result = $this->Users->save($user)) {
$this->Users->lastLogin($user['id']);
$authUser = $this->Users->get($result->id)->toArray();
$this->Auth->setUser($authUser);
$email = new Email();
$email->template('confirm')
->transport('mailjet')
->emailFormat('both')
->viewVars(['token' => $user->email_token])
->to($this->Auth->user('email'))
->from(['removed' => 'Welcome, ' . $user->username . '!'])
->subject('Please confirm your email!')
->send();
$this->Flash->success('You have successfully registered. Check your email to confirm email.');
return $this->redirect(['action' => 'profile']);
} else {
$this->Flash->error('The user could not be saved. Please, try again.');
}
}
$this->set(compact('user', 'userEmail', 'token'));
$this->set('_serialize', ['user']);
}
What could it be?
Error:
Connection timed out
Cake\Network\Exception\SocketException
Last time I got this error, the smtp address was blocked in my production server.
After whitelisting the smtp address everything was fine.
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();
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