I have a Component that I use to send off emails in CakePHP 2.0. It was working perfectly up until I put the site on a live host. Now, I get the error:
Invalid email: "[email protected]"
Obviously, the above email address is valid, so I don't know why Cake is throwing an Exception here. Note that I get the same result, regardless of what email address I use.
Component function that I use:
public function send($to, $subject, $body = null, $view = 'default', $vars = array(), $layout = 'layout'){
try{
$Email = new CakeEmail();
$Email->config('default');
$Email->template($view, $layout)->viewVars($vars);
$Email->from(array(Configure::read('Site.email') => Configure::read('Site.name')));
$Email->to($to);
$Email->subject($subject);
if(strlen(trim($body)) > 0){
$Email->send($body);
} else{
$Email->send();
}
} catch(Exception $e){
var_dump($e);
}
}
In my email config file, I'm using the default Mail transport.
Update: I seem to be having the exact same issue as the person in this question. Basically, I'm getting the error:
Invalid email: "[email protected]" An Internal Error has occured.
[email protected]
is the email stored in$to
orConfigure::read('Site.email')
variable? – Arun JainConfigure::read('Site.email');
I've manually added different email addresses, to no avail. I even commented out theCakeEmail::from
call, only to be given an exception for theCakeEmail::to
call, which was [email protected] – Wayne Whittyto
line when thefrom
is commented out, then I would suspect it happens earlier. Comment out the template line and see if the code works error free. – AgRizzofilter_var($email, FILTER_VALIDATE_EMAIL)
successfully validates the address? ... ps, please always mention your exact CakePHP version! – ndm