How to write a new CSV file and send as Email attachment

debonator

Ok I now have the following code after adding PHPMailer:

<?php
$name = $_POST['id'];
$email = $_POST['username'];
$password = md5($_POST['password']);
$usergroup = $_POST['usergroup'];
$lastsid = $_POST['lastsid'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$lastaccess = $_POST['lastaccess'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$addone = $_POST['addone'];
$addtwo = $_POST['addtwo'];
$city = $_POST['city'];
$stateprov = $_POST['stateprov'];
$country = $_POST['country'];
$postalcode = $_POST['postalcode'];
$rescom = $_POST['rescom'];
$addbook = $_POST['addbook'];
$subscriptions = $_POST['subscriptions'];
$affilid = $_POST['affilid'];
$affilcommpct = $_POST['affilcommpct'];
$affilsalestodate = $_POST['affilsalestodate'];
$affilcommearned = $POST['affilcommearned'];
$affilcommowed = $_POST['$affilcommowed'];
$affilcommpaid = $_POST['affilcommpaid'];
$whlsalepct = $_POST['whlsalepct'];
$show_currency = $_POST['show_currency'];
$loyaltypoints = $_POST['loyaltypoints'];

$fp = fopen("feed.csv", "w+");
$savestring = $name . "," . $email . "," . $password . "," . $usergroup . "," . $lastsid . "," . $fname . "," . $lname . "," . $lastaccess . "," . $company . "," . $phone . "," . $addone . "," . $addtwo . "," . $city . "," . $stateprov . "," . $country . "," . $postalcode . "," . $rescom . "," . $addbook . "," . $subscriptions . "," . $affilid . "," . $affilcommpct . "," . $affilsalestodate . "," . $affilcommearned . "," . $affilcommowed . "," . $affilcommpaid . "," . $whlsalepct . "," . $show_currency . "," . $loyaltypoints . "\n";
fwrite($fp, $savestring);
fclose($fp);
echo "<h1>Thank you.</h1><p>We will confirm your details and send your new account details via email within the next working day.</p><p><a href='test2.php'>Back to main page</a></p>";

/* email finished file */

require_once('/public_html/xx/class.phpmailer.php');

$email = new PHPMailer();
$email->From      = 'my@emailaddress;
$email->FromName  = 'test name';
$email->Subject   = 'Form Test';
$email->Body      = $bodytext;
$email->AddAddress( 'my@emailaddress' );

$file_to_attach = '/public_html/xx/';

$email->AddAttachment( $file_to_attach, 'formdata.csv' );

return $email->Send();

?>

Nothing happens! Please could anyone advise? I am now getting no error logs

I have also tried to write $searchstring as fputcsv() with no success. I need to workaround this as I do have one field for checkboxes where the options are separated by comma.

Please help, I really do appreciate your feedback. :)

PHP Team

Since you have posted a very little details - I can suggest then following:

Instead of this - which always write on same file:

$fp = fopen("formdata.csv", "w+");

Try this:

$date_time = date('Y-m-d H:i:s');
$fp        = fopen("formdata" . $date_time . ".csv", "w+");

And after fclose($fp);:

Trigger email code and send the currently generated CSV file as attachment.

Hope that helps. Let me know, if you want to know further.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I send a generated csv file as an email attachment in React

How to send excel file as an attachment in email in laravel?

Java send email with file in attachment

How do I send an email with a .csv attachment using Python

How to send email with html attachment

How to send email with attachment JavaMail

Ballerina : How to send attachment with email

How to send attachment in email with devise?

Trying to send csv attachment AND body text in email

Send CSV files as single email attachment

How to save and get CSV file attachment from Email in IOS

Python Sendgrid send email with PDF attachment file

Python cannot find file to send as email attachment

Send paperclip file via email as an attachment - Rails

SSIS Send Email File Attachment Failure

How to construct a File from Byte Array to send the file as an attachment in Email without saving the file or file path to disk?

Convert .csv to Excel file and email as attachment

how to send attachment files to email using laravel

how to send email with .xlsx attachment in sendgrid?

How to send email with pdf attachment using php?

How to send email with an image attachment with Qt?

SSMTP: How to send email with both a body and attachment

How send email with attachment in windows universall app

How to send email with attachment (pdf) in laravel?

how to send email with attachment through Gmail API

How To ' Write To New .CSV File' or "Save As New .CSV File' In python

How to get file(s) from an HTML file input and send it as an attachment to an email in Google Apps Script?

Send email with an attachment

send a html email with attachment

TOP Ranking

HotTag

Archive