Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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
如何使用cake php发送邮件以及从何处开始?_Php_Cakephp_Xampp - Fatal编程技术网

如何使用cake php发送邮件以及从何处开始?

如何使用cake php发送邮件以及从何处开始?,php,cakephp,xampp,Php,Cakephp,Xampp,我想尝试用蛋糕php发送邮件。我没有寄邮件的经验。所以,我不知道从哪里开始。是否需要制作邮件服务器?如果需要,如何制作邮件服务器以及如何发送邮件?请一步一步地解释。我真的不知道从哪里开始 我正在使用xampp,现在我在本地主机上测试我的站点。 我测试了以下链接: 但是发生错误,无法直接访问。 然后我从以下链接添加代码: 因此,我的代码如下: function _sendMail(){ $this->Email->to = 'user@gmail.com';

我想尝试用蛋糕php发送邮件。我没有寄邮件的经验。所以,我不知道从哪里开始。是否需要制作邮件服务器?如果需要,如何制作邮件服务器以及如何发送邮件?请一步一步地解释。我真的不知道从哪里开始

我正在使用xampp,现在我在本地主机上测试我的站点。

我测试了以下链接:

但是发生错误,无法直接访问。

然后我从以下链接添加代码:

因此,我的代码如下:

    function _sendMail(){
    $this->Email->to = 'user@gmail.com';
    $this->Email->bcc = array('secret@example.coom');
    $this->Email->subject = 'Welcome to our really cool things';
    $this->Email->replyTo = 'support@example.com';
    $this->Email->from = 'Online Application <app@example.coom>';
    $this->Email->template = 'simple_message';
    $this->Email->sendAs = 'both';

    $this->Email->smtpOptions = array(
            'port' =>'25',
        'timeout' => '30',
        'host' => 'ssl://smtp.gmail.com',
        'username' => 'my_mail@gmail.com',
        'password' =>'aaa',
    );
    $this->Email->delivery = 'smtp';
    $this->Email->send();
   }
函数_sendMail(){
$this->Email->to=user@gmail.com';
$this->Email->bcc=array('secret@example.coom');
$this->Email->subject='欢迎来到我们真正酷的东西';
$this->Email->replyTo='ssupport@example.com';
$this->Email->from='在线申请';
$this->Email->template='simple_message';
$this->Email->sendAs='both';
$this->Email->smtpOptions=array(
“端口”=>“25”,
“超时”=>“30”,
'主机'=>'ssl://smtp.gmail.com',
'用户名'=>'我的_mail@gmail.com',
“密码”=>“aaa”,
);
$this->Email->delivery='smtp';
$this->Email->send();
}
但错误仍然发生。但是,我没有制作任何邮件服务器。可以吗?

试试:

//load mail component in controller var $components = array('Mail'); //then do $this->Email->sendAs="html"; $this->Email->from="some@domain.com"; $this->Email->to="someone@domain.com"; $this->Email->subject="Your subject; $this->Email->send("Your message); //在控制器中加载邮件组件 var$components=array('Mail'); //那就做吧 $this->Email->sendAs=“html”; $this->Email->from=”some@domain.com"; $this->Email->to=”someone@domain.com"; $this->Email->subject=“您的主题; $this->Email->send(“您的邮件”);
//查看cakephp手册以了解更多参考信息:

使用前导下划线命名控制器函数是Cake向后兼容的指定函数应受到保护的方式,即该函数不应作为正常控制器操作访问。这意味着您无法使用URL
/foo/\u sendMail
或任何其他URL访问
FooController::\u sendMail()
。您应该看到这一点,这是一个非常好的错误消息:

用户控制器中的私有方法

错误:
FooController::\u sendMail()
无法直接访问


删除前导下划线,仅此而已。此问题与发送电子邮件无关。

我感觉这与您的XAMPP配置有关:

尝试打开“php.ini”,它应该在服务器文件中的某个位置

在php.ini文件中搜索名为“SMTP”的属性。通常可以找到“SMTP=localhost”行。将localhost更改为ISP的SMTP服务器名称。还有一个名为“SMTP_port”的属性,该属性应设置为25。我在php.ini文件中设置了以下值

SMTP = smtp.wlink.com.np
smtp_port = 25
重新启动apache服务器,以便重新加载PHP模块和属性

请尝试使用mail()函数发送邮件:

mail(“you@yourdomain.com”,”test subject”,”test body”);
如果您收到以下警告:

Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:\Program Files\xampp\htdocs\testmail.php on line 1
请指定以下标题,然后再次尝试发送邮件:

$headers = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1′ . “\r\n”;
$headers .= ‘From: sender@sender.com’ . “\r\n”;
mail(“you@yourdomain.com”,”test subject”,”test body”,$headers);

来源:

下面是一个使用CakePHP的电子邮件组件发送HTML电子邮件的示例代码


Ex控制器:EmailController.php

<?php
class EmailController extends AppController{

public $components=array('Email');

function send(){

//create an array of values to be replaced in email html template//
$emailValues=array('name'=>'MyName','phone'=>'MyPhone');
$this->set('emailValues',$emailValues);//pass to template //
$this->Email->to = 'to@address.com'; //receiver email id
$this->Email->subject = 'Subject Line';
$this->Email->replyTo = 'reply@address.com'; //reply to email//
$this->Email->from = 'SenderName<sender@address.com>'; //sender
$this->Email->template = 'sample';//email template //
$this->Email->sendAs = 'html';
if($this->Email->send()){
//mail send //
}

}

?>


现在在文件夹/Views/email/html中创建电子邮件模板/ ie模板路径应为 /Views/Email/html/sample.ctp

<?php

Hi <?php echo $emailValues['name'];?> <br>
Thanks for sharing your phone number '<?php echo $emailValues['phone'];?>' .
<br>


?> 
sample.ctp

<?php

Hi <?php echo $emailValues['name'];?> <br>
Thanks for sharing your phone number '<?php echo $emailValues['phone'];?>' .
<br>


?> 

感谢您共享您的电话号码“”。
?>
我已经像这样尝试了,但不正常,出现的错误无法访问directly@shariphwar你把问题混在一起了!对我来说,你似乎只是把电子邮件代码放在一个控制器操作中,该操作受保护且无法访问。你的电子邮件代码很好!给我们更多关于真实问题的信息!向我们展示控制器我知道这段代码在哪里,你是如何调用它的!谢谢。我明白了。消息真的到了吗?我尝试发送上面的功能,但消息没有到达我的gmail。为什么?这是另一个我不知道的主题。
Email->send()
实际返回
true
?请查看我下面的答案,它可能会对您有所帮助。XAMPP通常不配置为发送电子邮件。我想知道$this->email->smtpOptions,我不知道在哪里提供用户名和密码。有时用户名和密码由gmail填写,但有时不是。为什么?