CakePHP SMTP EMail Not Working on Server - email

I am able to send SMTP Emails from my local server machine in CakePHP while I am not able to do the same on my GoDaddy live server, in CakePHP.
Any ideas for the same?
Thanks
Answer is below as per my experience with GoDaddy:
Below code is working for me over GoDaddy server using CakePHP SMTP Email:
Email.php file inside config folder - CakePHP 2.4 MVC version:
// for Live Server GoDaddy.com domain
public $smtp = array(
'transport' => 'Smtp',
'host' => 'ssl://smtpout.asia.secureserver.net', // important
'port' => 465, // important
#'timeout' => 30,
'username' => 'no-reply#godaddy-domain.com',
'password' => 'password',
#'tls' => false,
#'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
And here is the controller file code below:
// Controller Code to Send Actual Email
// email configuration
$Email = new CakeEmail('smtp');
$Email->from(array('no-reply#godaddy-domain.com' => 'App Name'))
->sender('no-reply#godaddy-domain.com', 'App Name')
->to(array($email))
->bcc(array('xyz#xyz.com'))
->subject('Test Email from GoDaddy')
->emailFormat('both')
->send($hash.'<br><strong>My</strong> message 45 قبل الميلاد، مما يجعله أكثر من');
Hope it helps !
Thanks

Update your code to check for an error message:
if(!$this->Email->send()) {
CakeLog::write('debug', $this->Email->smtpError);
}
Then check the /app/tmp/logs/debug file on the server.

Related

SMTP server did not accept the password

I had written following code to send email.
static function sendEmail($email,$data,$type){
$Email = new CakeEmail();
$Email->config('general');
switch($type){
case 1:
$Email->template('confirmation_free', null);
$Email->subject('Confirmation of registration with XXXXXXXXXXXXX');
$Email->viewVars(array('Email'=>$data["Email"],'full_name'=>$data['full_name'],'Id'=>$data['Id'],'url'=>$_SERVER['SERVER_NAME'], 'password'=>$data['password']));
break;
case 2:
$Email->template('group-invite', 'default');
$Email->subject('XXXXXXXX Group Invite - Notification');
$Email->viewVars(array('Email'=>$data["Email"],'Username'=>$data['Username'],'Id'=>$data['Id'],'url'=>$_SERVER['SERVER_NAME']));
break;
case 3:
$Email->template('forgot_password', null);
$Email->subject('XXXXXXXX - Forgot Password');
$Email->viewVars(array('Email'=>$data["Email"],'Key'=>$data['Key'],'url'=>$_SERVER['SERVER_NAME'],'Id'=>$data['id']));
break;
}
$Email->to($email);
if($Email->send())
return true;
else
return false;
}
with following sendgrid smtp settings.
public $general = array(
'transport' => 'Smtp',
'from' => array('XXXXX#XXXXXXX' => 'XXXXXX Administrator'),
'host' => 'smtp.sendgrid.net',
'port' => 587,
'timeout' => 30,
'username' => 'XXXXXXX',
'password' => 'XXXXXX',
'client' => null,
'log' => false,
'emailFormat' => 'html'
);
It was working perfectly fine on my local and dev server. But after we installed SSL on the dev server, it started throwing following error "SMTP server did not accept the password "
Please note that I'm using a sendgrid free account. Do I need a paid account to send emails from a server with SSL?
You need to either use the tls option in your CakeEmail config or prefix the host with ssl:// https://book.cakephp.org/2.0/en/core-utility-libraries/email.html
Xylon, Please try this.
In Email.php
public $smtp = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'your email',
'password' => 'password',
'transport' => 'Smtp',
'log' => true,
'auth' => true,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
$Email = new CakeEmail('smtp'); // In Controller where you want send mail
$Email->viewVars(array("data" => $data));
$Email->template($template)
->emailFormat('html')
->to($reciever)
->from(array($mail_from => "Ecotrak"))
->subject($subject)
->send();
I hope this will resolve problem.
Email could not be sent: SMTP server did not accept the password. See trace
If you are facing that issue and your check everything is fine there is no issue anywhere but you still facing that issue.
Just do this simple process.
Go to your Google Account.
Select Security.
Go down
Click on Less Secure app access
Turn it on
Now check it... your issue will resolve

send email codeigniter 3 not working localhost use wamppserver

$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.googlemail.com',
'smtp_port' => 587,
'smtp_user' => 'example#gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->email->from('example#gmail.com', 'easyfact');
$this->email->to('example#gmail.com');
$this->email->cc('example#gmail.com');
$this->email->bcc('example#gmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
reulst website
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
and
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
i use wamppserver helf me
You are not using the $config variable anywhere. Call
$this->email->initialize($config);
That should solve your problem.
See also: Setting Email Preferences part of Codeigniter Email class documentation.

Sending Mail using CakePHP 3.0

I am developing a website with new version 3.0 of CakePHP Framework. I am working on localhost and would like to send an email after a user has filled a form. Below is the code in my controller to send the email.
public function index(){
if ($this->request->is('post'){
$email = new Email();
$email->from([$this->request->data["sender"] => "Sender"]
->to("myEmail#hotmail.com")
->subject($this->request->data["Subject"])
->send($this->request->data["message"]);
}
}
When this code is executed nothing happen, no error, no message in my mailbox. I have seen that it exist in cakephp3.0 a class called DebugTransport but I don't know how to use it in order to debug my code. Someone has already use it ?
Hi thanks everyone for your answer.
By using mailjet.com I was able to send e-mails in localhost. Below the different steps:
Step 1
Create an account on mailjet website
Step 2
In app.php add a new entry in the table EmailTransport. The different parameter host, port, username and password can be found on mailjet website.
'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,
],
'mailjet' => [
'host' => 'in-v3.mailjet.com',
'port' => 587,
'timeout' => 60,
'username' => 'xxxxx',
'password' => 'xxxxx',
'className' => 'Smtp'
]
],
Step 3
In your controller
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Network\Email\Email;
class ContactController extends AppController {
var $helpers = array('Html');
public function index(){
if($this->request->is('post')){
$userName = $this->request->data['firstname'] . " " . $this->request->data['lastname'];
$email = new Email();
$email->transport('mailjet');
try {
$res = $email->from([$this->request->data['email'] => $userName])
->to(['myEmail#hotmail.com' => 'My Website'])
->subject('Contact')
->send($this->request->data['message']);
} catch (Exception $e) {
echo 'Exception : ', $e->getMessage(), "\n";
}
}
}
You had to use a SMTP server for delivery your email from your localhost in your config email.
There are 2 ways to achieve this:
Use it from a real server with a mail configuration
Use SMTP server for your test on your localhost. there are a lot of SMTP server with let you use it.
see mailjet.com

Send smtp email with dynamic smtp options cakephp

I can send email configuring smtp options from email.php file and it works fine. But I want to send emails, where the smtp options, like host, port, username and password are taken from database.
I tried to use this, but does not work, just gives an error No connection could be made because the target machine actively refused it. The smtp options are correct.
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail('smtp');
$Email->smtpOptions = array(
'host' => $smtpAccount['host'],
'port' => $smtpAccount['port'],
'username' => $smtpAccount['username'],
'password' => $smtpAccount['password'],
);
$Email->to($email);
$Email->template('sending')->emailFormat('both');
$Email->subject($subject);
$Email->viewVars (
array(
'content' => $content
)
);
return $Email->send();
trying to set the host like $Email->host($smtpAccount['host']);
gives an error Call to undefined method CakeEmail::host()
Thanks
instead of $Email->smtpOptions should be used
$Email->config(array(
'host' => $smtpAccount['host'],
'port' => $smtpAccount['port'],
'username' => $smtpAccount['username'],
'password' => $smtpAccount['password'],
));

CakePHP: send mail through SMTP to MS OUTLOOK -> SMTP Error: 504 5.7.4 Unrecognized authentication type

I figured that I'll try to find out if I can send mails via cmd line before writing a question here. So I followed these steps and sent an e-mail by cmd to myself and a collegue of mine who's working on the same app I am. The message from cmd line came in the format it should have come.
( internal app, should send mails only to my collegues' OUTLOOK accounts )
Everything seems to be connected fine so I figured I have an error in my cakePHP code:
Everything on mails code I have so far is this:
app/config/email.php
public $smtp = array(
'transport' => 'Smtp',
'from' => array('from#test.sk'),
'host' => 'ip_address_of_my_host',
'port' => 25,
'timeout' => 30,
'username' => 'from#test.com',
'password' => 'password',
'client' => null,
'log' => true,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
UsersController.php (test send mail function)
public function test_send_email() {
$this->autoRender = false;
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('smtp');
$email->from(array('from#test.com' => 'APP TEST'));
$email->to('me#test.com');
$email->subject('Subject of testing');
$email->send('Message of testing');
}
After 5 seconds of loading I get: SMTP Error: 504 5.7.4 Unrecognized authentication type
Solved:
I guess the authentication wasnt required on EXCHANGE, so I just removed the password parameter and works fine.
During research I found out this article, so the next step would be to contact EXCHANGE admins.
http://blogs.technet.com/b/exchange/archive/2006/12/28/3397620.aspx
I was getting the same error when using telnet on port 25. After changing to port 587, I was able to use authenticated SMTP.