Unable to send mail in opencart - 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

Related

Trying to change the company (team) application status from Drupal 8 portal (APIGEE Edge)

I Can't change the company app status Approved/Revoked, I tried to load and update the team_app entity using EntityTypeManager, and the other values have been updated without any issues like (callback URL, Description, Dispalyname, and custom attributes) but still the app status won't change/update,
$app_storage = \Drupal::entityTypeManager()->getStorage('team_app');
$app_ids = $app_storage->getQuery()
->condition('companyName', $team->id())
->condition('name', $app_mame)
->execute();
if (!empty($app_ids)) {
$app_id = reset($app_ids);
$loaded_app = $app_storage->load($app_id);
$loaded_app->set('status', 'revoked');
$loaded_app->save();
}
Also, I tried to make a PUT API request to change the app status with the same results, No status value changed.
/** #var \Drupal\apigee_edge\SDKConnectorInterface $sdk_connector */
$sdk_connector = \Drupal::service('apigee_edge.sdk_connector');
try {
$sdk_connector->testConnection();
$client = $sdk_connector->getClient();
}
catch (\Exception $exception) {
dump('client is not defined');
die();
}
$endpoint = $client->getUriFactory()
->createUri("/organizations/{$sdk_connector->getOrganization()}/companies/{$team->id()}/apps/{$loaded_app->getName()}");
try {
$response = $client->get($client->getEndpoint() . $endpoint);
$results = json_decode((string) $response->getBody());
$results->status = 'revoked';
// PUT.
$endpoint = $client->getUriFactory()
->createUri("/organizations/{$sdk_connector->getOrganization()}/companies/{$team->id()}/apps/{$loaded_app->getName()}")
$response = $client->put($client->getEndpoint() . $endpoint, json_encode($results));
$results = (array) json_decode((string) $response->getBody());
}
catch (\Exception $exception) {
dump('error, not trigger');
}
Any help with this?

Unable to send HTML mail using 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.

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 :)

Webservice without token in moodle

I am beginner for webservice. I am writing a webservice in Moodle.
I would like to write one service for user sign up. In this case that user will not have any token or username+password.
How we can allow this user to call core_user_createUsers web service for sign up?
For other services I am using this code:
$domainname = 'http://mydomain/moodle';
require_once('./curl.php');
$curl = new curl;
$authurl = $domainname .'/login/token.php?username=admin&password=Admin123$&service=shcs_services';
$resp = $curl->get($authurl);
if($resp)
{
$resp = json_decode($resp);
$authToken = $resp->token;
}
/// PARAMETERS
$serverurl = $domainname . '/webservice/rest/server.php';
$params['wstoken'] = $authToken;
$params['wsfunction'] = 'core_user_createUsers';
$params['moodlewsrestformat'] = 'json';
$user1 = new stdClass();
$user1->username = 'testusername';
$user1->password = 'Testpassword1%';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = 'testidnumber1';
$user1->lang = 'en';
$user1->theme = 'standard';
$user1->timezone = '-12.5';
$user1->mailformat = 0;
$user1->description = 'Hello World!';
$user1->city = 'testcity1';
$user1->country = 'au';
$preferencename1 = 'preference1';
$preferencename2 = 'preference2';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'preferencevalue1'),
array('type' => $preferencename2, 'value' => 'preferencevalue2'));
$users = array($user1);
$params['users'] = $users;
$resp = $curl->post($serverurl, $params);
echo $resp;
in above code I would like to skip the below part
$authurl = $domainname .'/login/token.php?username=admin&password=Admin123$&service=shcs_services';
$resp = $curl->get($authurl);
if($resp)
{
$resp = json_decode($resp);
$authToken = $resp->token;
}
so that I don't want to pass the value $params['wstoken'] = $authToken; to web service .
But it is not allowing me without the token. Here's the error I get:
{"exception":"moodle_exception","errorcode":"invalidtoken","message":"Invalid token - token not found"}
Token is the only way to connect the web service to with your app. It is must. As I am working nowadays on web services and mobile app. So I experienced that token is the only way to validate the web services. The first step to connect with web service by validating it. And you are not passing the token at all. So your validation is going to be failed. and you are getting this error.

Consuming NetSuite service in WP7, CookieContainer not working

I'm using NetSuite webservice in my WP7 project.
This is the link that I use (the newer version):
https://webservices.na1.netsuite.com/wsdl/v2012_1_0/netsuite.wsdl
This worked perfectly in my C# console application, but not in WP7.
In WP7, it logs in successfully, but when adding anything (employee, customer, timebill, ...) I get the following error:
"Your connection has timed out. Please log in again"
UPDATE:
this is my console code:
NetSuiteService service = new NetSuiteService();
service.CookieContainer = new CookieContainer();
Passport passport = new Passport();
passport.account = "TSTDRVxxxxxx";
passport.email = "hamzeh.soboh#para-solutions.com";
RecordRef role = new RecordRef();
role.internalId = "3";
passport.role = role;
passport.password = "passxxxx";
Status status = service.login(passport).status;
and the following is my WP7 code:
NetSuitePortTypeClient service = new NetSuitePortTypeClient();
// service.CookieContainer = new CookieContainer();
Passport passport = new Passport();
passport.account = "TSTDRVxxxxxx";
passport.email = "hamzeh.soboh#para-solutions.com";
RecordRef role = new RecordRef();
role.internalId = "3";
passport.role = role;
passport.password = "passxxxx";
service.loginAsync(passport);
uncommenting the second statement causes a runtime error.
Try without cookies, something like this:
// Instantiate the NetSuite web services
netSuiteService = new DataCenterAwareNetSuiteService(*yourAccountNumber*);
netSuiteService.Timeout = 1000 * 60 * 60;
var appInfo = new ApplicationInfo();
//App info from application netsuite
appInfo.applicationId = *yourApplicationId*;
// Prepare login credentials for request level login
netSuiteService.passport = new Passport()
{
email = yourEmail*,
password = *yourPassword*,
account = *yourAccountNumber*
};
netSuiteService.applicationInfo = appInfo;
Prefs = new Preferences();
netSuiteService.preferences = Prefs;
SearchPreferences = new SearchPreferences();
netSuiteService.searchPreferences = SearchPreferences;
Prefs.warningAsErrorSpecified = true;
Prefs.warningAsError = false;
SearchPreferences.bodyFieldsOnly = false;