To send the email using the CakeEmail we first need to configure the smtp configuration that is in the Config/email.php.
public $smtp = array(
'transport' => 'Smtp',
'from' => array('youremailaddress@abcd.com' => 'My Site'),
'host' => 'smtpout.secureserver.net',
'port' => 25,
'timeout' => 30,
'username' => 'youremailaddres@abcd.com',
'password' => 'yourpassword',
'client' => null,
'log' => false,
'template' => 'registration'
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
We can now call this from our function in controller can set the data accoding to our need.
we also need to make html file in View/Email/html and View/Email/text if we setting the email format as html.
This is how we call the CakeEmail in our function.
public function sendEmail($email_data) {
$Email = new CakeEmail();
$Email -> config('smtp')
-> emailFormat('html')
-> from('ishan.bhatnagar@evontech.com')
-> to('ishan.bhatnagar@evontech.com')
-> subject("Contact Us")
-> viewVars(array('data'=>$email_data));
if($Email->send()){
return "sent";
}
else{
return "error";
}
}
and we also have to pass the data to the ctp in the html like this.
<html>
<p>
Name : <?php echo $data["firstname"] . " " . $data["lastname"]; ?>
</p>
<p>
Email : <?php echo $data["email"]; ?>
</p>
<p>
Number : <?php echo $data["number"]; ?>
</p>
<p>
Message : <?php echo $data["message"]; ?>
</p>
<p>
Thanks and Regards
</p>
</html>
In this we sent the first name , last name , email , phone number and a message as the message in the email.
0 Comment(s)