So I'm under the impression that bad things will happen if I don't use Zend_Mail_Transport_Smtp when sending lots of emails. Problem is...I can't figure out how to set it up. I am using Google Apps hosted email for my domain. So to access my email, I go to mail.mydomain.com, which takes me to a google login page.
This is the code that I am using, but it's not working.
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'webmaster#mydomain.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('mail.mydomain.com', $config);
Using "mail.mydomain.com" I get a "connection timed out" error (which makes me think its the wrong thing to use.
Using "smtp.mydomain.com" I get a "Could not open socket" error.
What am I doing wrong?
Since you are sending emails through gmail, you should use "smtp.gmail.com" and not your domain.
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'webmaster#mydomain.com', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Some more reference. Check the port using port scanner on remote end which are open, do a test if they reply packets, sometimes port 25 is not working so email fails, and also the SSL or TLS.
$config = array(
'ssl' => 'ssl', //TLS = tcp:// use port 25
//SSL = ssl:// use port 465 or 587
'port' => 465,
'auth' => 'login',
'username'=> 'x',
'password'=> 'b/c',
);
$tr = new Zend_Mail_Transport_Smtp('email-smtp.us-east-1.amazonaws.com', $config);
Zend_Mail::setDefaultTransport($tr);
Related
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
$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.
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'],
));
I am developing an application where my client is using Office 365 for his emails , etc... I am trying to connect Cakephp mail with office 365 SMTP but without any success.
Here is my code:
public $default = array(
'from' => array('info#*****.com' => 'Company Name'),
'transport' => 'Smtp',
'host' => 'tls://smtp.office365.com',
'port' => 587,
'username' => 'info#*****.com',
'password' => '*******',
'client' => null,
'log' => true,
'tls' => true
);
The error iam getting is Unable to connect to SMTP server. Also I tried the following hosts with and without tls:
ssl://smtp-mail.outlook.com
Smtp.mail.apac.microsoftonline.com (on this i was getting timeout error)
pod51022.outlook.com
Thanks.
try following :
'public $default = array(
'host' => 'smtp.office365.com',
'port' =>25,
'from' => array('info#*****.com' => 'Company Name'),
'transport' => 'Smtp',
'username' => 'info#*****.com',
'password' => '*******',
'tls'=>true );'
in case it don't work,
try after removing password,
make sure that
email id is authenticated to send anonymous mail on office365.
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.