1

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'));
}
siwy2411
  • 51
  • 1
  • 9
  • 1
    **Obscure your personal details** and show the email portion of config file – sjt003 May 06 '14 at 17:26
  • 1
    If you think this is a duplicate - you clearly did not read it. I wrote, that I have a perfectly working code (verified on localhost), my question is not realy concerning what might be wrong with the code, as it is nearly copy-paste from cake's cookbook. My question was, what might be wrong on server side, that prevents me from sending emails. – siwy2411 May 08 '14 at 07:53

1 Answers1

1

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.

Krimson
  • 7,386
  • 11
  • 60
  • 97
  • Thanks a lot! I was unfortunately unable to confirm external SMTP block with my provider, but MailGun solved my problem, which makes me think, that you were right about the block as well :) – siwy2411 May 08 '14 at 07:55