cakephp 电子邮件无法正常工作

发布于 2024-10-05 06:56:20 字数 854 浏览 4 评论 0原文

我的问题是:

在控制器中我有:

var $components = array('Email');

发送电子邮件的方法如下所示:

function send_emails() {
  $this->Email->from    = 'Somebody <[email protected]>';
  $this->Email->to      = 'Somebody Else <[email protected]>';
  $this->Email->subject = 'Test';
  $this->Email->send('Hello message body!');
 }

我正在使用 Cake 1.3 并使用 Apache 2.2.11 和 PHP5 在本地主机上运行它。你们知道为什么它不起作用吗?

当我输入

$this->Email->delivery = 'debug';

代码时,它会显示电子邮件信息,看起来一切正常。

您知道它不发送电子邮件的原因是什么吗?

my problem is:

in the controller I have:

var $components = array('Email');

the method to send emails looks like this:

function send_emails() {
  $this->Email->from    = 'Somebody <[email protected]>';
  $this->Email->to      = 'Somebody Else <[email protected]>';
  $this->Email->subject = 'Test';
  $this->Email->send('Hello message body!');
 }

I am using Cake 1.3 and running it on localhost with Apache 2.2.11 and PHP5. Do you guys have any idea why it doesn't work?

When I put

$this->Email->delivery = 'debug';

in the code, it displays the email info and it seems like everything is ok.

Do you have any ideas what can be the reason why it doesn't send email?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

骷髅 2024-10-12 06:56:20

如果您在远程服务器(即托管服务器)上进行开发,那么它应该可以工作,因为它会获取默认电子邮件。

因为您不是,所以您必须为邮件组件提供一些电子邮件功能。例如,您可以通过输入您的 gmail(或其他)smtp 详细信息(即服务器、登录名、密码)来做到这一点。

   /* SMTP Options for GMAIL */
   $this->Email->smtpOptions = array(
        'port'=>'465', 
        'timeout'=>'30',
        'auth' => true,
        'host' => 'ssl://smtp.gmail.com',
        'username'=>'[email protected]',
        'password'=>'your_gmail_password',
   );

    /* Set delivery method */
    $this->Email->delivery = 'smtp';

请参阅http://book.cakephp.org/view/1290/使用 SMTP 发送消息

如果您不确定要使用什么凭据,请在电子邮件提供商的帮助或常见问题解答中查找。通常可以通过搜索如何设置 Outlook 或 Thunderbird 来找到它。

If you're developing on a remote server, i.e. a hosting server, then that should work as it'll pick up the default email.

As you're not, you have to give the mail component some email capability. You can do this by, for example, feeding in your gmail (or whatever) smtp details, i.e. server, login, password.

   /* SMTP Options for GMAIL */
   $this->Email->smtpOptions = array(
        'port'=>'465', 
        'timeout'=>'30',
        'auth' => true,
        'host' => 'ssl://smtp.gmail.com',
        'username'=>'[email protected]',
        'password'=>'your_gmail_password',
   );

    /* Set delivery method */
    $this->Email->delivery = 'smtp';

See http://book.cakephp.org/view/1290/Sending-A-Message-Using-SMTP

If you're not sure what credentials to use, look it up in your email provider's help or faq. Typically it can be found by searching for how to set up Outlook or Thunderbird.

南城旧梦 2024-10-12 06:56:20

您是从 Windows 服务器发送吗?如果是这样,您是否在 php ini 中正确设置了 MTA?可以使用mail()函数发送邮件吗?

如果您使用的是 Windows 并且需要 MTA,hMail 非常适合开发,请注意,许多主机会拒绝来自您的本地计算机是垃圾邮件,因此如果没有 MX 记录、域密钥等,请勿在生产中使用。

Are you sending from a windows server? If so, have you properly setup your MTA in the php ini? Can you send mail using the mail() function?

If you are on windows and need an MTA, hMail is great for development, note that many hosts will reject mail from your local machine a spam so don't use on production without an MX record, domain keys etc.

吹梦到西洲 2024-10-12 06:56:20

您需要 SMTP 服务器来发送电子邮件。如果您尝试从本地主机发送它,有两个不错的选择:

您需要按照说明通过 SMTP 使用 CakePHP 发送电子邮件。您还可以修改 php.ini 设置以反映新设置。

You need an SMTP server to send email. If you are trying to send it from your localhost, two good alternatives are:

  • FreeSMTP: A Windows-based tool that lets your computer act like an SMTP Server
  • Gmail: You can use your Gmail address for testing purposes.

You need to follow the instructions to send email using CakePHP through SMTP. You could also modify your php.ini settings to reflect the new settings.

我纯我任性 2024-10-12 06:56:20

我遇到了同样的问题,我忘记在我的 xampp 服务器上启用 ssl,因为只需在 php.ini 文件中添加(或取消注释)extension=php_openssl.dll 行即可。希望有帮助。

I had the same problem, I forgot to enable ssl on my xampp server, for that it is necessary just to add(or uncomment) extension=php_openssl.dll line in your php.ini file. Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文