0

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);
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
  • please try var_dump($cc) and check the email send status , it will Boolean return – apurav gaur May 14 '15 at 11:58
  • it returned an array of data – soumikwebdeveloper May 14 '15 at 12:02
  • shared your return output array. – apurav gaur May 14 '15 at 12:03
  • Have you configured your email settings correctly? You could test it with something like mailcatcher – Colonel Mustard May 14 '15 at 12:14
  • Array ( [headers] => From: soumik.chakraborty@webguru-development.com X-Mailer: CakePHP Email Date: Thu, 14 May 2015 12:14:37 +0000 Message-ID: <555491adb7ac415ba3f605f0c0baee28@developersserver.com> MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit [message] => Forgot Password Hello Admin, Your new password : nmszwd – soumikwebdeveloper May 14 '15 at 12:17
  • I can't believe i'm the first person to say this but check the logs inside /app/tmp/logs this will show you if any errors are being generated you aren't seeing. Also might help adding the email setting minus the password of course for us to take a look at. – Matt Stephens May 15 '15 at 08:41

1 Answers1

0

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)

  1. 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' => trueenter code here );

  2. 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();

  3. 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

Scottish Dave
  • 166
  • 1
  • 2