Jump to content

Recommended Posts

OK so I want to be about to turn each line into a variable for example. I am retrieving emails sent to my email that look like this in the body content

 

Name

Address

Town

State

Zip

Car

 

I want to be able to make each line into a variable instead of doing this.


  	$query = mysqli_query($db,"SELECT * FROM email_leads WHERE email = '$company_email'");
  	while($rows = mysqli_fetch_assoc($query)){
 
  	$dbbody = nl2br($rows['body']);
    echo "<hr>$dbbody";

Any Ideas

Link to comment
https://forums.phpfreaks.com/topic/300916-turn-each-new-line-into-a-variable/
Share on other sites

Your query may be vulnerable to SQL injection attacks through the $company_email variable. Use a prepared statement instead.

 

Also, this line-by-line format is very bad for automatic parsing. Who generates the e-mails? Is there a chance to send the data in a proper machine-readable format like JSON, XML etc.? This would make the parsing much easier and more robust.

You're storing the body element of an email in your table without trying to identify the individual parts of that email first? How do you know the 'body' is actually in the format you expect it to be in? Is this email a free-form entry from some user? Do you send back a confirmation email that lets the user know that what they think they sent you is actually what you interpreted it as? And - when you store this email, how do you identify it? You have all the content in one field - that means no keys, no dates, no tracking of any kind. Kind of defeats the purpose of maintaining a database, don't you think?

 

If it were me and I absolutely had to obtain data this way, I would try to extract the data from the email and store it as a temporary record in a well-designed table with a reference key. I would then send the collected data items along with the reference key as a hidden field back to the user and ask for a reply that confirms their submission was correct. When that email comes back to a "special" address I would have another script designed to be triggered by emails coming in to it that would look for the reference key, locate the 'temporary' record and re-key it with the user's name (?) as the key and consider this entry as a valid one.

 

Your current method of obtaining this data is flawed. GIGO - remember that? No self-respecting data processer would ever do what you are doing.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.