Jump to content

PHP Array Email Data in CSV Format


diesel55

Recommended Posts

I know nothing about PHP and need some help on how to accomplish the following. I have a web form which collects data and then does a POST action to call a PHP file which takes the data and sends it to an email address. This all works fine, but right now when I get the data in my email I get it back as follows:

 

Date Submitted: 7/28/07

Name: Mark Jones

 

I do not want the Labels with the :  (I just want the data emailed)

 

Basically what I need to be able to do is easily copy this data into an Excel file when I get it. With the labels include with the :, the data all gets put into the same column in Excel, so I need to remove the labels. I'm pretty sure I have to modify something in my code listed in Red below, but not sure what or if thats the only thing.

 

 

PHP Code I'm using is below. Any help would be appreciated.

 

 

 

<?php

$to = "[email protected]" ;

$from = $_REQUEST['email'] ;

$headers = "From: [email protected]";

$subject = "Web Inquiry";

 

$fields = array();

$fields{"date"} = "Date Submitted";

$fields{"name"} = "Name";

$fields{"referred"} = "Referred By";

$fields{"work"} = "Work Phone";

$fields{"cell"} = "Cell Phone";

$fields{"email"} = "Email Address";

 

 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

$headers2 = "From: [email protected]";

$subject2 = "Thank you for contacting us";

$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.giftofassurance.com";

 

if($from == '') {print "You have not entered an email, please go back and try again";}

else {

$send = mail($to, $subject, $body, $headers);

if($send)

{print "Information Submitted Successfully"; }

else

{print "We encountered an error sending your mail, please notify [email protected]"; }

}

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/71175-php-array-email-data-in-csv-format/
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.