sharepoint online – Add JSPDF as a list item attachment

We are trying to save an attachment to multiple list items created concurrently. The PDF files are created dynamically using jspdf and stored against the list items

Below are the functions that create list item attachment by calling a common function named addItem().

Functions that call addItem()

function p1()
{
   CreateItem(fromEmail,distEmail,ccEmail,subject,body).then(function(resp){
                        
   console.log(resp);
   var Lid = resp.d.Id; // gets the list item ID
   var PDFStream = PDFArray; // Global Variable to get the jsPDF File
   var Fname = DFileName; // Global Variable to get the name of the attachment
   addItem(Lid,PDFStream,Fname);
  });
}

function p2()
{
   CreateItem(fromEmail,distEmail,ccEmail,subject,body).then(function(resp){
                        
   console.log(resp);
   var Lid = resp.d.Id; // gets the list item ID
   var PDFStream = PDFArray; // Global Variable to get the jsPDF File
   var Fname = DFileName; // Global Variable to get the name of the attachment
   addItem(Lid,PDFStream,Fname);
  });
}

Function to add attachment

function addItem(Lid,PDFFile,Fname) {
                        
            var File = PDFFile;
            var deferred = $.Deferred();           

                $.ajax({
                    url: _spPageContextInfo.webAbsoluteUrl +
                     "/_api/web/lists/getbytitle('ExtEmailsList')/items(" + Lid + ")/AttachmentFiles/add(FileName='"+Fname+"')",
                    type: 'POST',
                    data: File,
                    processData: false,
                    headers: {
                        "Accept": "application/json; odata=verbose",
                        "content-type": "application/json; odata=verbose",
                        "X-RequestDigest": $('#__REQUESTDIGEST').val(),
                        "content-length": File.length
                    },
                    success: function (data) {          
                    deferred.resolve(data);
                    },
        
                    error: function (err) {
                    deferred.reject(err);
                    }
               }); // ajax | POST      
        return deferred.promise();    
      };

The above function is called multiple times , However the function intermittently creates the attachment and the other times it fails and the attachment column is blank. Say function 1 calls addItem , it creates the attachment however the call from function 2 fails and vice versa.

I tried debugging , However there are no errors. Would appreciate if anyone could let us know how we can get this to work with multiple functions calling addItem().

Thanks in advance

php – Send attachment after form submission to user email and post data to admin

I have a form which on submit must send the data collected to the admin email (i grab it via post), and the user gets a gift – an email with an attachment is sent to him. How can i do this ?

Html code:

<div class="modal">
                            <form id="program-four-modal" method="post" action="makepdf.php">

                                <!-- Hidden Required Fields -->
                                <input type="hidden" name="project_name" value="test.com/offer/">
                                <input type="hidden" name="admin_email" value="info@semseo.md">
                                <input type="hidden" name="form_subject" value="Vreau cadoul - Lorem ipsum">
                                <!-- END Hidden Required Fields -->

                                <h3>Aplică</h3>

                                <input type="text" name="NumePrenume" placeholder="Nume Prenume..."
                                    title="Nume Prenume" required><br>
                                <input type="email" name="Email" placeholder="E-mail..." title="E-mail" required><br>
                                <input type="tel" name="NrDeTelefon" placeholder="Nr. de telefon..."
                                    class="checkphone" title="Nr de telefon" required>

                                <div class="program-four-modal-send-wrapper">
                                    <button type="submit" class="program-four-modal-send">Trimite</button>
                                </div>

                            </form>
                        </div>

                        <a href="#program-four-modal" class="btn program-four-btn" role="button" rel="modal:open">I want the gift</a>
                    </div>

Here i grab the variables from the form via post. Currently both user and admin get the same email https://prnt.sc/wmygg2 , https://prnt.sc/wmygpe .

Php code:

<?php

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;
use PHPMailerPHPMailerException;

require_once __DIR__ . '/vendor/autoload.php';

// Grab variables
$subject = $_POST('form_subject');
$name = $_POST('NumePrenume');
$email = $_POST('Email');
$phone = $_POST('NrDeTelefon');

// Create PDF
$data = '';
$data .= '<h1>Your details</h1>';

// Add data
$data .= '<strong>Name</strong> ' . $name . '<br />';
$data .= '<strong>Email</strong> ' . $email . '<br />';
$data .= '<strong>Phone</strong> ' . $phone . '<br />';

    // Instantiation and passing `true` enables exceptions
    $mail = new PHPMailer(true);

    try {
        //Server settings
        $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
        $mail->isSMTP();                                            // Send using SMTP
        $mail->Host       = 'smtp.hostinger.ru';                    // Set the SMTP server to send through
        $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
        $mail->Username   = 'admin@mustcode.xyz';                     // SMTP username
        $mail->Password   = 'password';                               // SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
        $mail->Port       = 587;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

        // Recipients
        $mail->setFrom('admin@mustcode.xyz', 'Gift Form');
        $mail->addAddress($email);     // Add a recipient

        // Attachment
        $mail->addAttachment('gift/sample.pdf');

        // Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $subject;
        $mail->Body    = $data;
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }

sharepoint online – microsoft graph api for share point to get attachment

I made a call like
https://graph.microsoft.com/beta/sites/4development106.sharepoint.com:/sites/DBSchenker:/lists/OEC_Docs?select=id,name,lastModifiedDateTime&expand=items(expand=fields(select=Title,Attachments))

and the response came as

  {
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.list)(id,name,lastModifiedDateTime,items(fields(Title,Attachments)))/$entity",
    "@odata.etag": ""a2b82575-6781-4c1e-9376-0cb9865a5f12,1"",
    "id": "a2b82575-6781-4c1e-9376-0cb9865a5f12",
    "lastModifiedDateTime": "2018-10-30T01:04:25Z",
    "name": "OEC_Docs",
    "items@odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.list)('a2b82575-6781-4c1e-9376-0cb9865a5f12')/items(fields(Title,Attachments))",
    "items": (
        {
            "@odata.etag": ""02115e22-f23a-4259-8ed6-daf8c43281ac,2"",
            "createdDateTime": "2018-10-30T01:04:25Z",
            "eTag": ""02115e22-f23a-4259-8ed6-daf8c43281ac,2"",
            "id": "1",
            "lastModifiedDateTime": "2018-10-30T01:04:25Z",
            "webUrl": "https://4development106.sharepoint.com/sites/DBSchenker/Lists/OEC_Docs/1_.000",
            "createdBy": {
                "user": {
                    "email": "vik.kumar@4development106.onmicrosoft.com",
                    "id": "7e2e677e-9869-42a7-af35-7b9f2a64438a",
                    "displayName": "Vik Kumar"
                }
            },
            "lastModifiedBy": {
                "user": {
                    "email": "vik.kumar@4development106.onmicrosoft.com",
                    "id": "7e2e677e-9869-42a7-af35-7b9f2a64438a",
                    "displayName": "Vik Kumar"
                }
            },
            "parentReference": {
                "siteId": "4development106.sharepoint.com,c0dcbfd8-d394-4b66-9292-d98b8d05be42,79ff79ae-9fc1-44e2-84f6-405f835b60cf"
            },
            "contentType": {
                "id": "0x010046F955EDF3E8184B9934ABF6AE97CF33",
                "name": "Item"
            },
            "fields@odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.list)('a2b82575-6781-4c1e-9376-0cb9865a5f12')/items('1')/fields(Title,Attachments)/$entity",
            "fields": {
                "@odata.etag": ""02115e22-f23a-4259-8ed6-daf8c43281ac,2"",
                "Title": "Test Attachment",
                "Attachments": true
            }
        }
    )
}

i can get title here but how do i get the link to the actual attachment? attachments field just indicate if there is one associated but not the actual one.

How to show gallery in image attachment page?

Advertising

y u no do it?

Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

Starts at just $1 per CPM or $0.10 per CPC.

Group Google Forms attachment by field value

I am going to have participants fill out a Google Form with attachments. I then want someone else to be able to able to fill out a separate form and upload more attachments. I want all of those attachments to be grouped together based on one field.

So for example, John Doe will fill out his application and upload his documents. Then his three references will fill out a separate form and upload their docu. I want to be able to automate these files all being grouped together in one folder based on the name field or last name field of the form.

Is this possible? I have never worked with customizing G Suite products before, but I want to be able to streamline the scholarship application process for a non-profit I volunteer for.

Thanks!

8 – How to use a views ajax pager to only reload the paged main view, not a display-all-items attachment

I have a view page displaying 5 items. The page has a views attachment displaying all items (a leaflet map display with about 200 nodes). The view uses ajax. I find that clicking the views pager renders both the view and the attachment, even though the contents of the attachment are not changing between different pages. This is a performance problem.

Does anyone know of a way to prevent the pager ajax request from requesting new attachment markup? Is it possible to do this so that if the pager response doesn’t return any attachment markup, it won’t just blank out the attachment?

Should I consider making a custom pager that loads via ajax the paged result of a block of the same view, then writes the specific html region and rewrites the url, leaving the attachment alone?

custom field – WordPress attachment problems

I’m building a CMS using wordpress…

I use Custom Fields to set different fields I need for an interactive:

enter image description here

An interactive example can be like this:

enter image description here

enter image description here

In the last image there is an image attachment example, but I also attach videos and audios.

Then in my code I convert all info into a json as follows:

   $attractorElements = (
    "Button"      => "ip25_button",
    "Title"       => "ip25_title",
    "Description" => "ip25_description",
    "Multimedia"  => "ip25_multimedia",
   );

   $json('Content') = (
      InteractiveClass::buildJsonElements("Attractor", $attractorElements),
      ...
   );
public static function buildJsonElements($screenType, $arrayFields) {
        $arrayElements = ();
        foreach ($arrayFields as $key => $value) {
            $arrayElements() = (
                "ID_Element" => (
                    $key => get_field($value, 'option')
                )
            );
        }

        return (
            "ScreenType" => $screenType,
            "Elements"   => $arrayElements
        );
    }

This works perfectly displaying a json with all info I need (example):

{
          "ID_Element": {
            "Button 1": {
              "EN": "Button 1 English",
              "AR": "العربية",
              "media": {
                "ID": 12932,
                "id": 12932,
                "title": "mauritania",
                "filename": "mauritania-1.jpg",
                "filesize": 92850,
                "url": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                "link": "http://localhost:8080/?attachment_id=12932",
                "alt": "",
                "author": "1",
                "description": "",
                "caption": "",
                "name": "mauritania",
                "status": "inherit",
                "uploaded_to": 0,
                "date": "2020-10-30 12:03:22",
                "modified": "2020-10-30 12:03:22",
                "menu_order": 0,
                "mime_type": "image/jpeg",
                "type": "image",
                "subtype": "jpeg",
                "icon": "http://localhost:8080/wp-includes/images/media/default.png",
                "width": 512,
                "height": 512,
                "sizes": {
                  "thumbnail": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1-150x150.jpg",
                  "thumbnail-width": 150,
                  "thumbnail-height": 150,
                  "medium": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1-300x300.jpg",
                  "medium-width": 300,
                  "medium-height": 300,
                  "medium_large": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "medium_large-width": 512,
                  "medium_large-height": 512,
                  "large": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "large-width": 512,
                  "large-height": 512,
                  "1536x1536": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "1536x1536-width": 512,
                  "1536x1536-height": 512,
                  "2048x2048": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "2048x2048-width": 512,
                  "2048x2048-height": 512
                }
              }
            }
          }
        },

         ......

My question is… What’s behind in WP that sometimes makes to display an element attached like this:

{
          "ID_Element": {
            "Button 1": {
              "EN": "Button 1 English",
              "AR": "العربية",
              "media": {
                "ID": 12932,
                "id": 12932,
                "title": "mauritania",
                "filename": "mauritania-1.jpg",
                "filesize": 92850,
                "url": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                "link": "http://localhost:8080/?attachment_id=12932",
                "alt": "",
                "author": "1",
                "description": "",
                "caption": "",
                "name": "mauritania",
                "status": "inherit",
                "uploaded_to": 0,
                "date": "2020-10-30 12:03:22",
                "modified": "2020-10-30 12:03:22",
                "menu_order": 0,
                "mime_type": "image/jpeg",
                "type": "image",
                "subtype": "jpeg",
                "icon": "http://localhost:8080/wp-includes/images/media/default.png",
                "width": 512,
                "height": 512,
                "sizes": {
                  "thumbnail": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1-150x150.jpg",
                  "thumbnail-width": 150,
                  "thumbnail-height": 150,
                  "medium": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1-300x300.jpg",
                  "medium-width": 300,
                  "medium-height": 300,
                  "medium_large": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "medium_large-width": 512,
                  "medium_large-height": 512,
                  "large": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "large-width": 512,
                  "large-height": 512,
                  "1536x1536": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "1536x1536-width": 512,
                  "1536x1536-height": 512,
                  "2048x2048": "http://localhost:8080/wp-content/uploads/2020/10/mauritania-1.jpg",
                  "2048x2048-width": 512,
                  "2048x2048-height": 512
                }
              }
            }
          }
        },

And other times display a simpler info (notice same image attached, but in different place)?:

 {
          "ID_Element": {
            "Button 2": {
              "EN": "Button 2 English",
              "AR": "العربية",
              "media": 12932
            }
          }
        },

Button 1 and Button 2 have the same structure in the Custom Field.

I tried to find out what could be wrong, but I wasn’t lucky.

Please, any one that could give me a hint? I would like to display the more complete info always.

Any help is welcome,

Thanks.

magento2.3 – Email Attachment not working in magento 2.3.4 contact us email

I’m using magento 2.3.4

i customized contact us magento 2 module(Magento_Contact)

i want to Attach file in Email

i followed this blog post

How to Add Attachments with Email in Magento 2.3.x

but

Create TransportBuilder.php file at VendorModuleModelMailTemplateTransportBuilder.php

this file

protected function prepareMessage()
    {
        parent::prepareMessage();
        $this->message->setPartsToBody();
        return $this;
    }

$this->message =>changed to MagentoFrameworkMailEmailMessageInterfaceFactory;

this class

getting error

Call to undefined method
MagentoFrameworkMailEmailMessageInterceptor::setPartsToBody()

custom post types – How to display only the parent owner of an attachment pdf file (using AC and ElasticPress)

I have a CPT (using ACF fields), that have a title, some other taxonomies and a pdf attached file (it’s also an attachment file because i need that Elasticpress search in it).
When I do a search, when a word is in the CPT title and in the PDF content, I have 2 results in my list. But it is the same CPT (the CPT and it’s pdf). I only need to retrieve the CPT title (that contains the pdf file). So I’m lost…..

<?php

        $args = (
            'post_type' => 'resources',
            'post_per_page' => 0,
            'tax_query' => (),
            'meta_query' => (
                'relation' => 'AND',
            ),
        );

        if (isset($_GET('keyword'))) {
            if (!empty($_GET('keyword'))) {
                $args('s') = $_GET('keyword');
            }
        }

        if (isset($_GET('authors'))) {
            if (!empty($_GET('authors'))) {
                $args('tax_query')() = (
                    'taxonomy' => 'authors',
                    'field' => 'slug',
                    'terms' => array($_GET('authors'))
                );
            }
        }

        if ($is_search) {
            $query = new WP_Query($args);
        } ?>

        <?php if ($is_search): ?>
            <?php if ($query->have_posts()) : ?>

                <?php while ($query->have_posts()) : $query->the_post();

                    $file = get_field('resource_pdf_file');
                    $link = $file('url');
                    $icon = $file('icon');
                    $size = $file('filesize');
                    $hr_size = size_format($size);
                    ?>

                    <article class="resources-item-list">
                        <img src="<?php echo $icon; ?>" alt="pdf icon">
                        <h4>
                            <a href="<?php echo $link; ?>"
                               target="_blank"><?php echo get_the_title($post->post_parent);
                                ?></a>
                        </h4>
                        <p><?php echo $hr_size ?></p>
                    </article>

enter image description here

The First result is the attachment match and the third is the Parent post that contain the attachment.

Thanks if someone can help…!

mysql – Create a CSV from SQL Data and email as attachment using PHP

I put together some functions that allows a PHP script to send the SQL data obtained from user inputs on a website via an email attachment as a CSV file. It works perfectly and I have no issues with the code. Alternatively with the right SQL query it would run every X amount of days with a cron job and only produce the data within a specific criteria such as every month.

The idea behind the code is for users that cannot extract their data from SQL and have limited experience running their businesses online. I would like some input from what I have put together from scripts and endless amounts of testing to see if the code is up to standard.

Firstly I create the fileName:

  function fileName()
{
    $path     = "csv/";
    $filename = "Subscribers" . date('Ymd') . ".csv";
    $filepath = $path . $filename;
    return $filepath;
}

After which I create the CSV file:

function createCSV()
{
    include_once "conn.php";
    global $conn;
    
    $filepath = fileName();
    $output   = fopen($filepath, "w");
    fputcsv($output, array(
        'Name',
        'Email',
        'Date Joined'
    ));
    $query  = "SELECT name, email, dateTime FROM tableData";
    $result = mysqli_query($conn, $query);
    while ($row = mysqli_fetch_assoc($result)) {
        fputcsv($output, $row);
    }
    return $output;
    fclose($output);
    
}

Followed by the code I cut and edited from a thread online for attaching the CSV using the built in mail function:

function sendCSV()
{

// Recipient 
$to = 'recipient@email.com';

// Sender 
$from     = 'sender@example.com';
$fromName = 'Test';

// Email subject 
$subject = 'PHP Email with Attachment';

// Attachment file 
$file  = fileName();
$files = glob('csv/*.csv');
unlink($files);

createCSV();

// Email body content 
$htmlContent = ' 
<h3>PHP Email with Attachment</h3> 
<p>This email is sent from the PHP script with attachment.</p> 
';

// Header for sender info 
$headers = "From: $fromName" . " <" . $from . ">";

// Boundary  
$semi_rand     = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Headers for attachment  
$headers .= "nMIME-Version: 1.0n" . "Content-Type: multipart/mixed;n" . " boundary="{$mime_boundary}"";

// Multipart boundary  
$message = "--{$mime_boundary}n" . "Content-Type: text/html; charset="UTF-8"n" . "Content-Transfer-Encoding: 7bitnn" . $htmlContent . "nn";

// Preparing attachment 
if (!empty($file) > 0) {
    if (is_file($file)) {
        $message .= "--{$mime_boundary}n";
        $fp   = @fopen($file, "rb");
        $data = @fread($fp, filesize($file));
        
        @fclose($fp);
        $data = chunk_split(base64_encode($data));
        $message .= "Content-Type: application/octet-stream; name="" . basename($file) . ""n" . "Content-Description: " . basename($file) . "n" . "Content-Disposition: attachment;n" . " filename="" . basename($file) . ""; size=" . filesize($file) . ";n" . "Content-Transfer-Encoding: base64nn" . $data . "nn";
    }
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $from;

// Send email 
$mail = @mail($to, $subject, $message, $headers, $returnpath);

// Email sending status 
echo $mail ? "<h1>Email Sent Successfully!</h1>" : "<h1>Email sending failed.</h1>";
}

I am quite new to PHP but managed to put something together that actually works. If you can point out my mistakes (which I do know there would be), or guide me to more simple techniques, I would really appreciate it and it will help me progress in my PHP learning path.