2

我正在尝试使用 CakeEmail 发送一封电子邮件,但它在$email->to()方法上失败了。可以在此图像上看到错误消息:http: //i47.tinypic.com/240yq86.png

基本上,我收到这两个错误:

Warning (2): preg_match() expects parameter 2 to be string, object given [CORE/Cake/Utility/Validation.php, line 815]
Warning (4096): Object of class CakeEmail could not be converted to string [CORE/Cake/basics.php, line 566]

这是我的sendEmail()方法:

function sendEmail($id, $email, $token)
{      
    print_r($email);
    $email = new CakeEmail();
    $email->from('admin@gmail.com');
    $email->to($email);
    $email->subject('Activate your account');     
    $activate_url = 'http://' . env('SERVER_NAME') .'/users/activate/'.$id.'/'.$token;
    $message = "Thank you for signing up. Click on the activation link to activate your account \n";
    return $email->send($message.$activate_url);
}
4

3 回答 3

3

你有一些基本的 php 错误:

将函数参数 2 名称更改为$to;
改为; print_r($email)_ 更改 $email->to($email); $email->to($to);`print_r($to)
to

于 2013-03-25T04:53:20.603 回答
1

编辑:完全错过了其他人发现的明显问题......

所以,我一直在寻找可能扰乱班级配置的其他问题......

根据http://book.cakephp.org/2.0/en/core-utility-libraries/email.htmlfrom()接受一个数组(尽管没有明确说明您必须使用数组)。

试试这条线:

$email->from(array('admin@gmail.com' => 'Admin at gMail'));

于 2013-03-25T04:46:03.167 回答
0

请注意,$emailin 参数被$email = new CakeEmail()更改为不同的变量而被覆盖$to

function sendEmail($id, $to, $token)
{      
    print_r($email);
    $email = new CakeEmail();
    $email->from('admin@gmail.com');
    $email->to($to);
    $email->subject('Activate your account');     
    $activate_url = 'http://' . env('SERVER_NAME') .'/users/activate/'.$id.'/'.$token;
    $message = "Thank you for signing up. Click on the activation link to activate your account \n";
    return $email->send($message.$activate_url);
}
于 2013-03-25T04:59:06.630 回答