Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email 使用cakephp发送电子邮件有困难_Email_Cakephp - Fatal编程技术网

Email 使用cakephp发送电子邮件有困难

Email 使用cakephp发送电子邮件有困难,email,cakephp,Email,Cakephp,当然这让我头疼,但我知道每个初学者都有同样的经历。我已经尝试了我找到的关于使用cakephp发送电子邮件的所有教程。嗯,什么都没用。我可以有一个关于cakephp电子邮件的更好教程的链接吗。手册也不完整:(我有点沮丧:( 我尝试过以下代码: <?php class EmailsController extends AppController{ var $components = array('Email'); function sendNewUserMail() {

当然这让我头疼,但我知道每个初学者都有同样的经历。我已经尝试了我找到的关于使用cakephp发送电子邮件的所有教程。嗯,什么都没用。我可以有一个关于cakephp电子邮件的更好教程的链接吗。手册也不完整:(我有点沮丧:(

我尝试过以下代码:

<?php
    class EmailsController extends AppController{

 var $components = array('Email');

function sendNewUserMail() {
    //$User = $this->User->read(null,$id);
    $this->Email->to = 'csorila17@gmail.com';
    $this->Email->bcc = array('secret@example.com');  
    $this->Email->subject = 'Welcome to our really cool thing';
    $this->Email->replyTo = 'support@example.com';
    $this->Email->from = 'Cool Web App <charm_sorila@yahoo.com>';
    $this->Email->template = 'simple_message'; // note no '.ctp'
    //Send as 'html', 'text' or 'both' (default is 'text')
    $this->Email->sendAs = 'both'; // because we like to send pretty mail
    //Set view variables as normal
    $this->set('User', $User);
    //Do not pass any args to send()
    $this->Email->send();
    echo "hi";
 }
    }
?>
因此,每当我尝试在浏览器中运行此操作时,我在url中键入的内容如下:`http://localhost/email/sendNewUserMail


我的浏览器给我的是一个空白页,没有发送任何内容csorila17@gmail.com.可能是什么问题?如果可能的话,伙计们,我可以看一看使用cakephp发送电子邮件的完整代码吗?这个问题让我发疯。如前所述,提前谢谢你,重要的是要知道版本号。确保ug在您的配置文件中设置为“2”,因此您可以看到一些输出。

如果您在本地运行此应用程序,我相信您需要设置邮件服务器才能工作,否则您可以对任何提供商使用smtp邮件选项。为此,您必须配置邮件设置

app\config
中,您可以创建一个文件
email.php

<?php 
    class EmailConfig {

        public $default = array(
            'host' => 'ssl://smtp.gmail.com',
            'port' => 465,
            'username' => 'your email address', //example@gmail.com
            'password' => 'password',
            'transport' => 'Smtp',
            'from' => array('From Email Address' => 'Name to be displayed in the Email'),
            'log' => true
        );

    }

您是否检查了日志中是否有错误消息?您使用的是什么版本的CakePHP?1.x和2.x发送电子邮件的方式不同。您的代码看起来像是在尝试使用1.x解决方案,但在尝试回答您的问题之前,我想知道。我使用的是1.3.0版本。嗯,日志似乎不起作用。您是这样输出日志的:$this->logs();…我做的和我在研究中发现的一样,但同样的事情。即使上面的几行:echo“hi”,它也没有显示出来…我认为你的url是错误的
http://localhost/emails/sendNewUserMail
(注意“s”)首先。第二,打开“调试”以查看错误,而不是空白页。我已经将调试模式设置为2,但它仍然给我一个空白页。它甚至不回显任何内容:(
<?php 
    class EmailConfig {

        public $default = array(
            'host' => 'ssl://smtp.gmail.com',
            'port' => 465,
            'username' => 'your email address', //example@gmail.com
            'password' => 'password',
            'transport' => 'Smtp',
            'from' => array('From Email Address' => 'Name to be displayed in the Email'),
            'log' => true
        );

    }
$email = new CakeEmail();
$email->to('example@gmail.com');
$email->subject('Email testing Subject');       
$email->send('Email testing content');