This my code in cakephp method in one of my controller , but no email is coming to account. I really need help on this.
When I printing $cc
variable , its giving an output of array , but dont know how to know whether mail has been send successfully or not .
Since no mail came to the mailaccount , so i guess mail is not sende properly , or there is some bug in my code .
$email = new CakeEmail('default');
$body = "<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
</head>
<body>
<div style='background: #F6F6F6; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; margin: 0; padding: 0;'>
<table cellspacing='0' cellpadding='0' border='0' height='100%' width='100%'>
<tr>
<td align='center' valign='top' style='padding: 20px 0 20px 0'>
<table bgcolor='FFFFFF' cellspacing='0' cellpadding='10' border='0' width='624' style='border:1px solid #E0E0E0;'>
<tr>
<td width='147' align='center'><img src='".Router::url('/', true)."images/logo.png'></td>
</tr>
<tr bgcolor='#666666'>
<td colspan='2' align='center'>
Forgot Password
</td>
</tr>
<tr bgcolor='#CCCCCC'>
<td colspan='2'>Hello Admin, </td>
</tr>
<tr bgcolor='#E7E6EC'>
<td> </td>
<td width='415'>Your new password : ".$new_password."</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>";
$email->from(array($adminemail =>"Cakeshop"));
$email->emailFormat('both');
//$email->to($check['AdminLogin']['admin_email_address']);
$email->to(array($adminemail));
$email->subject('Recover Password');
$cc=$email->send($body);
When trying something like this I would use a different method, instead of writing your markup and assigning it to the $body variable. Create a layout and view for emails, and use that as your markup. (SEE BELOW)
Make sure you have setup your email.php file correctly, I like to use a Gmail account to send them at first just to be sure the email functionality is working.
public $gmail = array( 'host' => 'smtp.gmail.com', 'port' => '465', 'username' => 'Your Gmail email', 'password' => 'Your Gmail password', 'transport' => 'Smtp', 'tls' => true enter code here
);
Once you have done this add the following code to your controller.
$data = 'I am sending this string to the view of the email, I can then access this string using $myData';
$Email = new CakeEmail(); $Email->template('welcome', 'fancy') ->emailFormat('both') ->to('Email address to be sent to') ->from('Email address coming from.'), ->viewVars(array('myData' => $data)) ->send();
Build the markup for your email you can find the files here.
app/View/Emails/html/welcome.ctp app/View/Layouts/Emails/html/fancy.ctp
If you have any further questions please feel free to email me:
simpsond1988@gmail.com
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.