Jump to content

emailing a .csv


studentofstone

Recommended Posts

I am trying to set up a script that will capture a form's data, create a .csv and email it. The code I have returns no errors but will not send the email. Any help please.

<?php


$cr = "\n";
$csvdata = "First Name" . ',' . "Last Name" . ',' . "Email" . ',' . "Telephone" . ',' ."Comments" . $cr;
$csvdata .= $first_name . ',' . $Last_Name . ','. $email . ',' . $telephone .',' . $comments  . $cr;

$thisfile = 'member.csv';

$encoded = chunk_split(base64_encode($csvdata));


// create the email and send it off

$subject = "new member";
$from = "[email protected]";
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-Type: multipart/mixed;
    boundary="----=_NextPart_001_0011_1234ABCD.4321FDAC"' . "\n";

$message = '

This is a multi-part message in MIME format.

------=_NextPart_001_0011_1234ABCD.4321FDAC
Content-Type: text/plain;
        charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hello

We have attached for you the PHP script that you requested from http://rrwh.com/scripts.php
as a zip file.

Regards

------=_NextPart_001_0011_1234ABCD.4321FDAC
Content-Type: application/octet-stream;  name="';

$message .= "$thisfile";
$message .= '"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="';
$message .= "$thisfile";
$message .= '"

';
$message .= "$encoded";
$message .= '

------=_NextPart_001_0011_1234ABCD.4321FDAC--

';

// now send the email
mail($email, $subject, $message, $headers, "-f$from");
echo $mail_sent ? "Mail sent" : "Mail failed";

?>


 

 

Link to comment
https://forums.phpfreaks.com/topic/223311-emailing-a-csv/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.