I am trying to collect my form inputs into a csv file and for some reason the csv file records some of the styling and does not display numbers (phone number and date). I am not sure where I got it wrong. Here is what I have so far.

<?php 
    $name = $_POST["name"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $meeting_type = $_POST["meeting_type"];
    $time = $_POST["time"];
    $message = $_POST["message"];
    $to      = 'yahoo@gmail.com';
    $subject = 'Contact Form Submission';

    $v1 = "
            <html> 
            <body> 
            <style>
                h1 {color:#000066;}
                table {border:1px solid black; background: #e3f0ff;}
            </style>
            <h1>Hello, this form has been submitted!</h1>
            <img src= 'site.png' />
            <table rules='all' style='border-color: #ffb300;' cellpadding='10' width='500px'>
                <tr style='background: #ffb300;'><td><strong>First Name:</strong> $name</td>
                <tr style='background: #fafafa;'><td><strong>Email:</strong> $email</td>
                <tr style='background: #fafafa;'><td><strong>Phone:</strong> $phone</td>
                <tr style='background: #fafafa;'><td><strong>Reason for Contact:</strong> $meeting_type</td>
                <tr style='background: #fafafa;'><td><strong>Best Time to Contact:</strong> $time </td>   
                <tr style='background: #fafafa;'><td><strong>Comments:</strong> $message</td>
            </table>   
            </body> 
            </html> ";
    $message = $v1; 
    $headers  = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 
    mail($to, $subject, $message, $headers); 
    echo "Message has been sent..."; //Page RE DIRECT 
    echo $v1;
//******************************************************************************************************************************//

    $name = $_POST["name"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $phone = $_POST["phone"];
    $meeting_type = $_POST["meeting_type"];
    $time = $_POST["time"];
    $message = $_POST["message"];
    $subject = 'Message Confirmed!';
    $v1 = "
            <html> 
            <body> 
            <style>
                #disclosure {font-size: 8px; color: #333;}
                h1 {color:#000066;}
                table {border:1px solid black;}
            </style>
            <img src= 'site.png' />
            <table rules='all' style='border-color: #ffb300;' cellpadding='10' width='500px'>
                <tr style='background: #ffb300;'><td><strong>Email Confirmation</strong>
                <tr style='background: #fafafa;'><td>Hello <strong> $name</strong>, your message has been recieved! We will contact you shortly! <br><br>Best, <br>Me<br>An awesome person<br><br>Follow Us On:<br><a href='http://www.facebook.com'><img src='facebook_hover.png' width='18' height='18'></a><a href='http://twitter.com'><img src='twitter_hover.png' width='18' height='18'></a><a href='http://google.com'><img src='gplus_hover.png' width='18' height='18'></a><br><div id='disclosure' align='right'>©me™ All Rights Reserved 2014-2014 </div>
            </table>   
            </body> 
            </html> ";
    $message = $v1; 
    $headers  = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 
     mail($email, $subject, $message, $headers);    

      $count= count(file("main_form.csv"));                       
        $today = date("d M Y h:i A");
        echo $today;
        echo $v1;

$cvsData = "\n" . $count . "," . $today . "," . $name . "," . $email . "," . $phone . "," . $meeting_type . "," . $time . "," . $message;

 $fp = fopen("main_form.csv", "a" );
 if($fp){
     fwrite($fp, $cvsData);
     fclose($fp);
     }                   

?>

A csv file is meant to hold data. What do you mean by styling?

Maybe provide a sample output so se can see what you see?

What JorgeM says, plus: my best guess is that it has something to do with the contents of $message. Have you tried omitting $message from your CSV to see if styling still comes through?

what error is it giving?Can you give screen shot of error?By the way thanks

A csv file is meant to hold data.

Right, that's what i meant to say :P I am using it to hold the data that is collected when the form is submitted.

Have you tried omitting $message from your CSV to see if styling still comes through?

I think the issue has to do with $message because the styling of the email shows up rather than the comment that gets submitted. I haven't had success figuring out what to do with $message... i keep leading myself into error messages :P

what error is it giving?Can you give screen shot of error?

I don't think i should refer to it as an "error" but rather the unwanted result :P

I didn't realize that I forgot to attach what it looked like when I run it. Here is the preview: Capture.PNG

I managed to get through the issue where the numbers show up as "#" and all i did was increase the width of each cell on excel... basically, the "only" issue is that the message does not show, the styling of the email shows, and when the form is run on the actual site, you see a glimpse of the tables that get sent to me for literally half a second (if you guys want to see what i mean, i can send you each a link).

You're overriding the $message with the HTML in $v1.

$message = $_POST["message"];

$v1 = "
<html>
<body>
<style>
#disclosure {font-size: 8px; color: #333;}
h1 {color:#000066;}
table {border:1px solid black;}
</style>
<img src= 'site.png' />
<table rules='all' style='border-color: #ffb300;' cellpadding='10' width='500px'>
<tr style='background: #ffb300;'><td><strong>Email Confirmation</strong>
<tr style='background: #fafafa;'><td>Hello <strong> $name</strong>, your message has been recieved! We will contact you shortly! <br><br>Best, <br>Me<br>An awesome person<br><br>Follow Us On:<br><a href='http://www.facebook.com'><img src='facebook_hover.png' width='18' height='18'></a><a href='http://twitter.com'><img src='twitter_hover.png' width='18' height='18'></a><a href='http://google.com'><img src='gplus_hover.png' width='18' height='18'></a><br><div id='disclosure' align='right'>©me™ All Rights Reserved 2014-2014 </div>
</table>
</body>
</html> ";

$message = $v1; 

Store $_POST['message'] in $user_message or something so you can use it for the CSV.

O my god I thought that $message was meant to be overwritten by $v1, but now that I read these new messages you may very well be right, Traevel :p.

Can't i just delete that line that goes $message = $v1;?

Yeppie! it worked when i deleted that line. Now onto another issue. When the form is submitted, i for some reason am able to get a glimpse of the 2 tables that are meant to be sent to the user/person who submit the form and to me. I don't know if that makes sense, but I think its worth a shot.

So, to reword what i am trying to say... as soon as I hit submit, the page refreshes and shows me a quick glimpse of this before it sends me back to the form: Screen_Shot_2014-12-31_at_10.02_.16_PM_.png

shows me a quick glimpse

That's the echo $v1's I put in to test the other time. Just delete both and it shouldn't print to screen anymore.

I think it is working after what @Traevel has commented out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.