Unable to send HTML mail using opencart - opencart

I am trying to send HTML mail using opencart using the following code
$mail = new Mail();
$namess = $this->request->post['name'];
$emailss = $this->request->post['email'];
$phoness = $this->request->post['phone'];
$phoness2 = $this->request->post['phone2'];
$enquiryss = $this->request->post['enquiry'];
$conve = $this->request->post['contactviae'];
$convp = $this->request->post['contactviap'];
if($conve == '1')
{
$convee = "Yes";
}
else
{
$convee = "No";
}
if($convp == '1')
{
$convpp = "Yes";
}
else
{
$convpp = "No";
}
$body = "Hello Admin <br/><br/> You have recieved a request for product. The details for your product is as follow :
<br/><br/>
<table border='1'>
<tr><td>Name</td><td>$namess</td></tr>
<tr><td>Email</td><td>$emailss</td></tr>
<tr><td>Phone No</td><td>$phoness</td></tr>
<tr><td>Secondary Phone</td><td>$phoness2</td></tr>
<tr><td>Enquiry</td><td>$enquiryss</td></tr>
<tr><td>Contact Via Email</td><td>$convee</td></tr>
<tr><td>Contact Via Phone</td><td>$convpp</td></tr>
</table><br/><br/>
Thanks & Regards
";
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject("Request a product");
$mail->setHtml($body);
//$mail->setText(html_entity_decode($body, ENT_QUOTES, 'UTF-8'));
$mail->send();
When I am trying to use the code it is sending mail with HTML tags
How can I send HTML mail with the above code?

$body = "Hello Admin <br/><br/> You have recieved a request for product. The details for your product is as follow :"
. "<br/><br/>"
. "<table border='1'>"
. "<tr><td>Name</td><td>$namess</td></tr>"
. "<tr><td>Email</td><td>$emailss</td></tr>"
. "<tr><td>Phone No</td><td>$phoness</td></tr>"
. "<tr><td>Secondary Phone</td><td>$phoness2</td></tr>"
. "<tr><td>Enquiry</td><td>$enquiryss</td></tr>"
. "<tr><td>Contact Via Email</td><td>$convee</td></tr>"
. "<tr><td>Contact Via Phone</td><td>$convpp</td></tr>"
. "</table><br/><br/>"
. "Thanks & Regards";
Use above code to define html code value.

Related

How can I get email from Google People API?

I am using Google people API client library in PHP.
After successfully authenticating, I want to get email
Help me to find out the problem from my code below.
Can i use multiple scopes to get email, beacuse when i m using different scope it gives me error
function getClient() {
$client = new Google_Client();
$client->setApplicationName('People API');
$client->setScopes(Google_Service_PeopleService::CONTACTS);
$client->setAuthConfig('credentials.json');
$client->setAccessType('offline');
$client->setPrompt('select_account consent');
$str = file_get_contents('credentials.json');
$json = json_decode( $str, true );
$url = $json['web']['redirect_uris'][0];
if (isset($_GET['oauth'])) {
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect_uri = $url;
header('Location: ' . filter_var($redirect_uri,FILTER_SANITIZE_URL));
} else if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$people_service = new Google_Service_PeopleService($client);
} else {
$redirect_uri = $url.'/?oauth';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
return $people_service;
}
$optParams = array(
'pageSize' => 100,
'personFields' => 'addresses,ageRanges,biographies,birthdays,braggingRights,coverPhotos,emailAddresses,events,genders,imClients,interests,locales,memberships,metadata,names,nicknames,occupations,organizations,phoneNumbers,photos,relations,relationshipInterests,relationshipStatuses,residences,sipAddresses,skills,taglines,urls,userDefined',
);
$people_service = getClient();
$connections = $people_service->people_connections-
>listPeopleConnections('people/me', $optParams);

Unable to send mail in opencart

I have created a new information page named as request. In this I have added the following code
{
$mail = new Mail();
$namess = $this->request->post['name'];
$emailss = $this->request->post['email'];
$phoness = $this->request->post['phone'];
$phoness2 = $this->request->post['phone2'];
$enquiryss = $this->request->post['enquiry'];
$conve = $this->request->post['contactviae'];
if($conve == '1')
{
$emailsss = "Yes";
}
else
{
$phonesss = "Yes";
}
if(!isset($emailsss)){
$emailsss = "No";
}
if(!isset($phonesss)){
$phonesss = "No";
}
echo $body = "Hello Admin <br/><br/> You have recieved a request for product. The details for your product is as follow :
<br/><br/><table border='1'><tr><td>Name</td><td>$namess</td></tr><tr><td>Email</td><td>$emailss</td></tr>
<tr><td>Phone No</td><td>$phoness</td></tr><tr><td>Secondary Phone</td><td>$phoness2</td></tr><tr><td>Enquiry</td><td>$enquiryss</td></tr><tr><td>Contact Via Email</td><td>$emailsss</td></tr>
<tr><td>Contact Via Phone</td><td>$phonesss</td></tr></table><br/><br/>Thanks & Regards";
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject("Request a product");
$mail->setHtml($body);
$this->response->redirect($this->url->link('information/request/success'));}
But after submitting the button it is redirecting to success page but not getting any mail. Plz help me what I am missing
able to send mail through contact page
Do you set the email configuration in the admin? It's in System > Settings > (Edit the store) > Mail

Prestashop 1.5 Webservice Updating Customer id_default_group PHP

I need to automatically update the prestashop->customers->customer->id_default_group value using PHP via the Prestashop webservice. The script knows the new value and it is done before/as the page loads.
I can get a customer record, or I can get just the "id_default_group" of a customer record but I run into trouble when I try changing the record value and updating the webservice. I get back "HTTP/1.1 400 Bad Request".
It seems like I am incorrectly trying to update the xml or object.
It would be preferable to do all this by only getting and updating the "id_default_group" and not having to retrieve the complete customer record.
I have:
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://www.site.com/');
define('PS_WS_AUTH_KEY', 'yuyiu');
require_once('../PSWebServiceLibrary.php');
// First : We always get the customer's list or a specific one
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'customers'); // Full customer record
//$opt = array('resource'=>'customers','display'=> '[id_default_group]','filter[id]' => '['.$_SESSION["iemIdCustomer"].']'); // Customer id_default_group value
if (isset($_SESSION['iemIdCustomer'])){
$opt['id'] = $_SESSION['iemIdCustomer'];
}
$xml = $webService->get($opt);
// The elements from children
$resources = $xml->children()->children();
// $resources = $xml->children()->children()->children(); // If just getting id_default_group
}
catch (PrestaShopWebserviceException $e)
{
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error';
}
// Second : We update the data and send it to the web service
if (isset($_SESSION['iemIdCustomer'])){
// Update XML with new values
$xml->customers->customer->id_default_group = 4;
//$resources = $xml->children()->children()->children();
// And call the web service
try
{
$opt = array('resource' => 'customers');
//$opt = array('resource'=>'customers','display'=> '[id_default_group]','filter[id]' => '['.$_SESSION["iemIdCustomer"].']');
$opt['putXml'] = $xml->asXML();
$opt['id'] = $_SESSION['iemIdCustomer'];
//$opt['display'] = 'id_default_group';
$xml = $webService->edit($opt);
// if WebService succeeds
echo "Successfully updated.";
}
catch (PrestaShopWebserviceException $ex)
{
// Dealing with errors
$trace = $ex->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error<br />'.$ex->getMessage();
}
}
This is basic for those in the know so I hope you can help.
Thanks in advance,
Lance
Ok I go the following to work.
The following line seem to do the trick:
$xml->children()->children()->id_default_group = 4;
Follows is the line with the rest of the code to do the task.
// Get the customer's id_default_group
try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'customers');
$opt['id'] = $_SESSION["iemIdCustomer"];
$xml = $webService->get($opt);
// Get the elements from children of customer
$resources = $xml->children()->children()->children();
}
catch (PrestaShopWebserviceException $e)
{
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error';
}
// Update the data and send it to the web service
// Update XML with new value
$xml->children()->children()->id_default_group = 4;
// And call the web service
try
{
$opt = array('resource' => 'customers');
//$opt = array('resource'=>'customers','display'=> '[id_default_group]','filter[id]' => '['.$_SESSION["iemIdCustomer"].']');
$opt['putXml'] = $xml->asXML();
$opt['id'] = $_SESSION['iemIdCustomer'];
//$opt['display'] = 'id_default_group';
$xml = $webService->edit($opt);
// if WebService don't throw an exception the action worked well and we don't show the following message
echo "Successfully updated.";
}
catch (PrestaShopWebserviceException $ex)
{
// Here we are dealing with errors
$trace = $ex->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error<br />'.$ex->getMessage();
}
Hope that it assists someone.
i think you have this error because you are editing the bad node ;)
try with
$xml->customer->id_default_group = 4;
That should be OK :)

facebook registration plugin location field not writing to mysql

Everything else works fine except for the location. The actual city/state does not come across. Instead the word Array is displayed. My field type in the database is text but I've tried every field type through mysql. The HTML file is JSON where it comes to the field names. I am very new at this so any help is appreciated.
This is my php file:
<? ob_start(); ?>
<?php
define('FACEBOOK_APP_ID', '');
define('FACEBOOK_SECRET', '');
// No need to change function body
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
if ($_REQUEST) {
$response = parse_signed_request($_REQUEST['signed_request'],
FACEBOOK_SECRET);
/*
echo "<pre>";
print_r($response);
echo "</pre>"; // Uncomment this for printing the response Array
*/
$name = $response["registration"]["name"];
$email = $response["registration"]["email"];
$gender = $response["registration"]["gender"];
$prosecutor = $response["registration"]["prosecutor"];
$location = $response["registration"]["location"];
// Connecting to Database
$con = mysql_connect("my_hosting_site","Database","password");
if (!$response)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Database", $con);
mysql_query("INSERT INTO my_table (name, email, gender, prosecutor, location)
VALUES ('$name', '$email', '$gender', '$prosecutor', '$location')");
mysql_close($con);
}
$URL="https://www.facebook.com";
header ("Location: $URL");
?>
<? ob_flush(); ?>
Facebook
Basically, it's an array.
[location] => Array
(
[name] => Delhi, India
[id] => 1.1604xxxxxx286E+14
)
Use this for getting location stored in your db, like I have written below:
$location = $response["registration"]["location"]["name"];

Is there any way to get facebook user email with django-facebookconnect?

I already integrate django-facebookconnect on my project, but when user login email field stay empty, i mean this app does not save user email ??
It seems like it does:
user = User(username=request.facebook.uid,
password=sha.new(str(random.random())).hexdigest()[:8],
email=profile.email)
But when i check it does not saves email, is this an error or a facebook restriction?
You need to get the extended permission from facebook.
<?php
$app_id = "YOUR_APP_ID";
$app_sec = "APP_SEC";
$canvas_page = "APP_CANVAS_PAGE_URL";
$scope = "&scope=user_photos,email,publish_stream"; $auth_url"http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page).$scope;
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode(".", $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, "-_", "+/")), true);
if (empty($data["user_id"])) {
echo(""); }
$access_token = $data["oauth_token"];
$user_id = $data["user_id"];
$user = json_decode(file_get_contents( "https://graph.facebook.com/me? access_token=" . $access_token));
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($COOKIE["fbs" . $app_id], "\""), $args);
ksort($args);
$payload = "";
foreach ($args as $key => $value) {
if ($key != "sig") {
$payload .= $key . "=" . $value;
}
}
if (md5($payload . $application_secret) != $args["sig"]) {
return null;
}
return $args;
}
$cookie = get_facebook_cookie($app_id, $app_sec);
?>