I was developing one web application in cakephp 2.2.3. that application I was using CakeEmail. But Now I want to implement SparkPost plugin for email deliver.
I spend lots of time in google but not getting any satisfied result. All are code I found cakephp 3.0 or higher.
Below I have posted some links for cakephp 3.x -
https://github.com/syntaxera/cakephp-sparkpost-plugin
https://github.com/narendravaghela/cakephp-sparkpost
Please help me and give me any idea about to implement sparkpost in cakephp 2.x.
SparkPost supports SMTP so you could configure CakePHP for that. Here's a (guessed-at) configuration stanza:
class EmailConfig {
public $sparkpost = array(
'host' => 'smtp.sparkpostmail.com',
'port' => 587,
'username' => 'SMTP_Injection',
'password' => 'YOUR_API_KEY_WITH_SMTP_PRIVILEGES',
'transport' => 'Smtp',
'tls' => true
);
}
Then in your controller code, you would instantiate a CakeEmail instance using the config stanza named above:
$email = new CakeEmail();
$email->config('sparkpost');
$email->from(...)->to(...)->subject(...)->send();
Related
I am looking around for some answers to my problem. I really do not know what in my settings or code is wrong but i can't make the sending of email work.
Here is my mail.php values
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => array('address' => 'here is my email', 'name' => 'Some name here'),
'encryption' => 'tls',
'username' => null,
'password' => null,
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
Here is the services.php
'mailgun' => array(
'domain' =>'my domain here' ,
'secret' => 'my secret key here',
),
Here is my code for Sending.
$data = array(
'msg' => 'You have successfully registered ',
'url' => 'someURL'
);
try{
Mail::send('emails.REGISTRATION_SUCCESS', $data, function($message){
$message->from('admin#something.com', 'y System');
$message->to('myemail#gmail.com')->subject(' Registration Successful!');
});
}catch(Exemption $e){echo $e->getMessage();}
echo 'hello';
I am having this error whenever I run the code.
Class 'GuzzleHttp\Client' not found
I really do not know where in this code i am wrong. I am currently stuck right now. it still not sending any email. I really dont know now. please hep me. I am looking at some tutorials and almost same question post but nothing is working. any suggestions?
From the Laravel mail documentation:
Driver Prerequisites
The API based drivers such as Mailgun and SparkPost are often simpler and faster than SMTP servers. If possible, you should use one of these drivers. All of the API drivers require the Guzzle HTTP library, which may be installed via the Composer package manager:
composer require guzzlehttp/guzzle
in you composer.json file add this "guzzlehttp/guzzle": "~5.3|~6.0" in require portion then composer update for more info click here
or just in your terminal on the laravel root folder run composer require "guzzlehttp/guzzle": "~4.0"
Just do as #Martin suggested
$ composer require guzzlehttp/guzzle
from command-line on your project path.
This will install the required packages. Also refer guzzle github link
Just in case, you are doing this directly on production (which is really very dangerous), you may follow #bashar's answer.
I am trying to write a PHP script for a live production server to check if the IP whitelisting for the open SMTP relay settings on a Google account works properly.
Since the server is currently live I don't want to change any of the /etc/postfix/main.cf settings for the existing email solution, and thought I would try to write an isolated Zend_Mail script that could test it independently, but I'm having difficulties getting Zend_Mail to acknowledge an SMTP connection without login credentials.
I've tried different variations on
$domain = 'foo.bar.com';
$config = array('ssl' => 'tls', 'username' => 'noreply#bar.com');
$transport = new Zend_Mail_Transport_Smtp($domain, $config);
Zend_Mail::setDefaultTransport($transport);
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('noreply#bar.com', 'NoReply');
$mail->addTo('jono#gmail.com', 'jono');
$mail->setSubject('TestSubject');
$mail->send();
but it only times out, and I can't find any config options that would help.
So the question is, is it possible to send mail using Zend_Mail through a Google SMTP relay without using any login credentials, if the IP is whitelisted in the Gmail settings? If not, is there any other way to do this through the command line or another PHP library?
Try to change your $config array like this :
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'noreply#bar.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
I am using mail() to send emails in my php application. Since I do not have access to my hosting server settings ( php.ini ), is it possible to configure the SMTP settings from my application ? So far I have found this approach
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'your#gmail.com', //your gmail account
'password' => 'snip' // your password
));
but once I am not sure how to include this Mail class and second I need to do this everywhere I send mails in the app so seems not good for me.
The PHP manual says you can set everything except the path to the sendmail binary in your directory-local .htaccess files. Your sample code appears to use the PEAR::Mail extension, which may not be available on your system.
I have a problem with getting Cake Email to work properly.
I set everything up exacly as specified in cookbook (http://book.cakephp.org/2.0/en/core-utility-libraries/email.html section 'Configuration'). When I test it on localhost (xampp) everything works like a charm, the problem is, when I upload files on my web server, and try to execute it (send email) I get "Network is unreachable".
It seems to me, that there is probably some issue on server-side, but what could that be, and how to fix that?
Thanks in advance.
EDIT:
My code, as requested.
/app/Config/email.php
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'wykresl***14#gmail.com',
'password' => '***********',
'transport' => 'Smtp',
'timeout' => '30'
);
in Controller
public function test()
{
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail('gmail');
$Email->from(array('wykreslanka.2014#gmail.com' => 'Wykreślanka 2014'));
$Email->to('si***1#gmail.com');
$Email->subject('test');
$Email->template('newsletter');
$Email->emailFormat('html');
$Email->viewVars(array('post_id'=>0,'post_title'=>'Tytuł','post_body'=>'Body','quote_is'=>false));
$Email->send();
$this->Session->setFlash('Poszło','success');
return $this->redirect(array('action' => 'all'));
}
Typically, most web hosting services block external SMTP connections for some reason I'm still trying to understand. One such webhost I know is JustHost.
They want you to use their local smtp server... I would suggest you get in contact with your webhosting service a I'm 100% sure its something on their part and not with your code.
My webhost refused to listen so the best alternative I used was MailGun http://www.mailgun.com/
This allows you to send an email using an php-api that they provide. However you wont be able to use your gmail address.
I am facing problem while connecting cake php version-2.0.0-dev application on server. When I connect with localhost database, it works fine on server, but if I try to connect it with the database of the different server which is being hosted by another host, it gives following error:
Fatal error: Call to a member function getAttribute() on a non-object in
/home/dev.ukssmain/public_html/stock_system_ukrs/cake/libs/model/datasources/dbo/dbo_mysql.php
on line 259**
My configuration in database.php file is like
public $default = array(
'driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'test.com',
'port' => '3306',
'login' => 'test',
'password' => 'test',
'database' => 'test',
'prefix' => ''
);
Can anybody help me to get through this.
Firstly, you should update to 2.0.6 (latest stable 2.0.x), or 2.2.2 which is the latest stable. You can find them here.
2.0.0-dev is unstable and outdated, you should use a stable version instead. I don't know why you'd want to run a production site with a -dev version, you're asking for problems.
Database configuration info can be found here.