Edit mail.inc to enable SMTP server for sending mail - drupal

i want to place the following codes into include/mail.inc of Drupal7 so that i can send mail from SourceForge's project web space. Don't ask me to install SMTP Authentication Support, and i don't have access to php.ini , I wonder where should these codes be placed? Thanks in advance!
include('Mail.php');
$recipients = array( 'someone#example.com' ); # Can be one or more emails
$headers = array (
'From' => 'someone#example.com',
'To' => join(', ', $recipients),
'Subject' => 'Testing email from project web',
);
$body = "This was sent via php from project web!\n";
$mail_object =& Mail::factory('smtp',
array(
'host' => 'prwebmail',
'auth' => true,
'username' => 'YOUR_PROJECT_NAME',
'password' => 'PASSWORD', # As set on your project's config page
#'debug' => true, # uncomment to enable debugging
));
$mail_object->send($recipients, $headers, $body);

if this code could success send email without drupal7 (you must make sure it)
then you could do it in three ways:
write a drupal 7 module ,copy mail.php into *.module, and make the rest code as a function,that's the way as the handbook of drupal.
just copy all of the code to you theme/page.tpl.php , and run it directly , a little dirty
hack drupal core , include/mail.inc , just change function drupal_mail_send

Related

How to use file upload option in WooCommerce payment gateway admin options?

I am developing a plugin to integrate a payment gateway in WooCommerce. I have done one before.
But in this one, I need to upload a key file in gateway settings and that is used to hash the data before making payment request to related portal.
I have following code which allows to choose file, but I doubt this is working in the back end.
'sandbox_pvt_key' => array(
'title' => __( 'Test Private Key', 'woocommerce-custom-gateway' ),
'type' => 'file',
'desc_tip' => true,
'description' => __( 'Please upload the test private key file; this is needed in order to test payment.', 'woocommerce-custom-gateway' ),
'default' => '',
),
The output looks like the following:
Can anybody lemme know if this is supported option in the gateway settings? If not, can anybody guide me on how I can customize it via some hook/filters or any other way.
This can be achieved in the process_admin_options()
public function process_admin_options() {
$this->upload_key_files();
$saved = parent::process_admin_options();
return $saved;
}
private function upload_key_files() {
//handle uploads here
}

Handle incoming Array from Guzzle

So i have been trying to get guzzle working, i can send a post request which sends some kind of array and I would like to know, how can i receive it at an endpoint? i can handle things like if(isset($_POST['nameHere'])) but not the array thingy
$client = new Client();
$response = $client->request('POST', 'http://httpbin.org/post', [
'form_params' => [
'email' => 'test#gmail.com',
'name' => 'Test user',
'password' => 'testpassword',
],
'debug' => true
]);
echo '<pre>' . print_r((string)$response->getBody(), true) . '</pre>';
}
ps: My custom laravel application is the sender, my wordpress site is the receiver.
Got it working, i was missing the .php ending in my url, because i chose not to test with httpbin but directly with my api.
and in wordpress i dont get anything because this is the sendercode i published not the receiver (wordpress). i wouldnt know how to test it. thanks anyway

Drupal 7 Migrate Module shows "No migration groups defined". Why is my Migration Class not registering?

I am trying to migrate content (at this point user accounts specifically) from a legacy site into Drupal 7 using the Drupal Migrate module but for some reason the custom site migration class is not being registered. The only indication that something is wrong is the lack of any output when running drush migrate-status, and the output "No migration groups defined" when visiting http://<drupal_root_url>/admin/content/migrate in a web browser. The migrate, migrate_ui, and pinpics_migration modules have all been enabled via the Drupal 7 admin dashboard. I have tried using drush to clear all caches and register the migration classes, as well as registering the migration classes using the web UI to no avail. drush was run from the folder with the settings.php file /<drupal_root_path>/sites/default/
drush cc all && drush migrate-register && drush migrate-status
I have the following files located in
/<drupal_root_path>/sites/all/modules/custom/pinpics_migration/
pinpics_migration.info
pinpics_migration.migrate.inc
pinpics_migration.module
I have tried placing the file containing the custom migration class implementation pinpics_users.inc in the same directory as the files above, as well as in:
/<drupal_root_path>/includes/
Here are the file contents:
pinpics_migration.info:
<?php
name = "Pinpics Migration"
description = "Module to migrate legacy site to Drupal 7 site"
package = "Migration"
core = 7.x
dependencies[] = migrate
files[] = pinpics_migration.module
files[] = pinpics_users.inc
?>
pinpics_migration.migrate.inc:
<?php
function pinpics_migration_migrate_api() {
$api = array( 'api' => 2 );
return $api;
}
?>
pinpics_migration.module:
<?php
define("SOURCE_DATABASE", "pinpics_db");
?>
pinpics_users.inc: (Stripped of some helper functions, and specific implementation details)
<?php
/// Stripped some helper functions that were used by pinpicsUserMigration::prepareRow() below
class pinpicsUserMigration extends Migration {
public function __construct() {
parent::__construct(MigrateGroup::getInstance('user_migration_group'));
$this->description = t('Migrate pinpics.com users');
$source_fields = array(
'uid' => t('User ID'),
'roles' => t('The set of roles assigned to a user.'),
'password' => t('MD5 hash of User Password'),
'email' => t('User email address'),
'name' => t('Username'),
'created' => t('Timestamp that legacy account was created.'),
'status' => t('The staus of the User account'),
'logintime' => t('Timestamp that the User last logged in.')
);
$query = db_select(SOURCE_DATABASE.'.users', 'u')
->fields('u', array('uid', 'roles', 'password', 'email', 'name', 'created', 'logintime', 'status'))
->condition('status', '0', '=')
->condition('inactive', '0', '=')
->condition('email', '', '<>')
->condition('loginip', '', '<>')
->orderBy('uid', 'ASC');
$this->source = new MigrateSourceSQL($query, $source_fields);
$this->destination = new MigrateDestinationUser(array('md5_passwords' => TRUE));
$this->map = new MigrateSQLMap($this->machineName,
array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'non null' => TRUE,
'description' => 'Legacy Unique User ID',
'alias' => 'u',
)
),
MigrateDestinationUser::getKeySchema()
);
$this->addFieldMapping('uid', 'uid');
$this->addFieldMapping('name', 'name');
$this->addFieldMapping('pass', 'password');
/// Many addFieldMapping() statement stripped out for brevity.
}
public function prepareRow($current_row) {
/// Stripped implementation details for massaging data to prepare for Drupal 7.
return TRUE;
}
}
?>
I am new to Drupal, and have been using the following references to implement the migration.
Drupal 6 to Drupal 7 via Migrate 2
Getting started with Migrate
Has anyone encountered this problem before, or know how to go about finding out what is wrong?
Try these steps:
Visit your sites modules page /admin/modules to trigger rebuilding of cached PHP.
Disable and enable your module to get a new class registered.

Facebook Posting using FB API phpSDK

i created my app on fb with permissions ready to publish on users behalf, the thing is, a regular post has Like and Comment links, like buttons on bottom of the post, i want to add my custom link : VOTE NOW, its a poll post
how can i do that?
someone gave an answer but for js sdk not php, n i cant find it on facebook dev documentation
some gave a close enough solution, but ddnt seem to work on php with modifications
FB.ui({
method: "feed",
link: "LINK_URL",
...
actions: [
{ name: "Read Now", link: "URL TO THE READ NOW " }
]
}, function(response) { console.log(response); });
It seems it's working with /me/feed but with my custom /me/xxxxxx:submitted_a_poll/ its not working
When you make a call with the PHP SDK, you also pass a similar set of parameters:
$attachment = array(
'link' => 'http://your-cool-site.com',
'description' => 'This is the description',
...
'actions' => array(
array(
'name' => 'Vote Now!',
'link' => 'http://your-cool-site.com/vote.php'
)
)
);
$result = $facebook->api('/me/feed/', 'post', $attachment);
All you really have to do is add the relevant action settings to your parameters.

Drupal 6 Mimemail with attachment

Can anyone help me with drupal mimemail for attachment i am using below mentioned code to send attachment file on specific email, but somehow its not working, kinldy help me thanks in advance
$body = "test body with attachments";
$subject = "My test message";
$attachments[]=array(
'filepath' => file_directory_path().'/document.pdf',
'filename' => 'wonderful.pdf',
'filemime' => 'application/pdf',
);
mimemail("xxxxx#gmail.com", "xxxxxx2#gmail.com", $subject, $body, NULL, array(), NULL, $attachments,'');
I'm doing something very similar. My code is basically:
$message['attachments'][] = array(
'filepath' => $zipfilepath,
'filename' => 'my-attachment.zip',
'filemime' => 'application/zip',
);
from within my hook_mail module callback. See http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_mail/6
Are you sure that you've done the following:
enabled "mimemail" module;
checked the option in admin to "Use mime mail for all messages";
selected "mimemail" as the "E-mail Engine" (at the bottom of the admin page).
Mine is working just fine. I have SMTP module installed as well, and it works with either module selected as the Email Engine.

Resources