PHP - New Lines Within Strings \n And Making Them Appear In Phpmail()
I'm working on a project where I have concatenated a string that lists all of the members of a group and want to email them to the group administrator. An example string may look like this:
$string = 'Mark Ruiz | class A | January 7, 2010\n\nJason Adams | class B | January 9, 2010.\n\nDan Hernandez | class A | March 4, 2010.'; When I put that into the message of my email: $body = "Hello $admin,\n\nThis is the list of members to your group:\n$string." The \n\n that separates each member in the string is still considered part of the string, so the email doesn't recognize that it should start a new line. Does anybody know a good work around to this problem? Thanks so much! Similar TutorialsHi! What i can't figure out, is how to delete between 2 given strings in another file. Explanation: I have a file, it contains following: Code: [Select] ### Start of content 0 ### Some Radom Lines with text 1 ### End of content 0 ### ### Start of content 1 ### Some Radom Lines with text 2 ### End of content 1 ### ### Start of content 2 ### Some Radom Lines with text 3 ### End of content 2 ### And so on, now i need code, which can find line i give and delete between. Something like this: If, i give string: Code: [Select] ### Start of content 0 ### Then it will delete this line to the Code: [Select] ### End of content 0 ### Hope you can help! All the best: Mart L. I have the following code, which is supposed to allow me to send files with e-mails, but it is only attached a MIME attachment and not the PDF I want to attach. Here is the code: Code: [Select] <?php $name = $_REQUEST['txtName']; $email = $_REQUEST['txtEmail']; $to = "$email"; $subject = "A test email"; $random_hash = md5(date('r', time())); $headers = "From: noreply@geekology.co.za\r\nReply-To: noreply@geekology.co.za"; $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; $attachment = chunk_split(base64_encode(file_get_contents("http://www.webdesignsbyliz.com/blog/wp-content/themes/twentyten/eBook.pdf"))); $output = " --PHP-mixed-$random_hash; Content-Type: multipart/alternative; boundary='PHP-alt-$random_hash' --PHP-alt-$random_hash Content-Type: text/plain; charset='iso-8859-1' Content-Transfer-Encoding: 7bit Hello World! This is the simple text version of the email message. --PHP-alt-$random_hash Content-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is the <b>HTML</b> version of the email message.</p> --PHP-alt-$random_hash-- --PHP-mixed-$random_hash Content-Type: application/pdf; name=http://www.webdesignsbyliz.com/blog/wp-content/themes/twentyten/eBook.pdf Content-Transfer-Encoding: base64 Content-Disposition: attachment $attachment --PHP-mixed-$random_hash--"; echo @mail($to, $subject, $output, $headers); ?> What am I doing wrong? I use phpmail script to send attachments from site to e-mail. The script itself works. I noticed that e.g. in the case of Gmail messages are coming but without attachments. Instead, in addition to the content, there is a very long message containing only the hash string. In addition, not all mailboxes display content correctly. In some cases, the content also adds, for ex.: Quote--PHP-alt-41babb7e7ab4c64e3af6ea533924bebdContent-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit and the html coding in plain text. Can it be standardized so as not to display unnecessary information? Here's my code: <?php $to = $_POST['email']; $subject = 'Attachment from site domain.com'; $subject = sprintf("=?utf-8?B?%s?=", base64_encode($subject)); $random_hash = md5(uniqid(time())); $headers = "From: MySite <site@domain.com>\r\nReply-To: site@domain.com"; $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; $filename = $_POST['file_id'] . ".pdf"; $path = "/home/ftp/wp-content/uploads"; $file = $path . "/" . $filename; // read file into $data var $f = fopen($file, "rb"); $data = fread($f, filesize( $file ) ); fclose($f); $attachment = chunk_split(base64_encode($data)); ob_start(); ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Hello, Here the mail text. --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: 8bit <h2>Hello,</h2> <p>Here's the mail text</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Transfer-Encoding: base64 Content-Type: application/pdf; name="<?php echo $filename; ?>" Content-Disposition: attachment <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php $message = ob_get_clean(); if (@mail($to, $subject, $message, $headers )) { echo "<p><b>File send!</b></p> Check your e-mail."; } else { echo "<p><b>Error!</b></p> File not send."; } ?> What can I change to make delivery with an attachment work for all mailboxes? Hey guys!! So basically what I am doing here is pulling the directory out of a url. URL ex: http://www.xxx.com/T...IS_WHAT_I_WANT/ is there a way I can make something like a ticket in pdf format that can have $name or the likes echo in it? if you could help get me started, that would be great! I was thinking how can I make a script that will build strings incrementing through each letter starting with "a" and ending with "zzzzzz" or what ever ending length I want such as 12. So if your were to output everything, you could find the words: "dog" "spider" "superman" "hippo" etc What would be the best way to do this, so I don't have to have a loop that is 500 blocks deep to show a word that is 500 letters example Quote a ... z aa ab ac ... az ba bb bc ... ... aaa aab aac Hello, I was wondering if someone could help me to "get" the webaddress of a current webpage and then pull off pieces of the page. All of my pages look like: http://localhost:8888/algebra_book/Chapters/Quadratic_Functions/introductory_problem.php BUT, the stuff to the left of Quadratic Functions WILL change in the future. So all will look like: *Quadratic_Functions/introductory_problem.php Then, I'd like to pull off a $chapter variable, which in this case is Quadratic_Functions and a $page_name variable which in this case will be introductory_problem. Thanks so much. hello, here is what i have, obviosly it doesnt work. Code: [Select] $year=$_POST['y']; $yr=substr($year,-2); $mth=$_POST['m']; $init=$_POST['initial']; $jobnumber=$yr$mth2343$init; echo "$jobnumber"; P.S. thanks to everybody for their help lately! Hi I am having troubles using a string in a cookie.. This doesnt work: setcookie("background", "$image_name", $expire, "/", ".gedoo.com"); Neither does this: setcookie("background", "" . $image_name . "", $expire, "/", ".gedoo.com"); If I write something before $image_name like: setcookie("background", "hello" . $image_name . "", $expire, "/", ".gedoo.com"); It will save "hello" in the cookie.. So in other words, $image_name doesnt look like it is defined.. But the funny thing is that this works on the same page: echo "File Uploaded Successfully!<br><img src='images/$image_name'>"; Anyone have any idea on what I am doing wrong? Not sure if there is a better way to do this, but I want to check whether the value in a Sticky Field is the same as what is in the Database. If what is in the Sticky Field is *exactly* what is in the Database, then the User didn't update that field, and so I would NOT do an UPDATE. Seem reasonable? Here is where I grab the value out of the Form... Code: [Select] // **************************** // Process Each Form Field. * // **************************** foreach($_POST['answerArray'] as $questionID => $response){ // Copy trimmed Form array to PHP array. $answerArray[$questionID] = trim($response); And here is where I grab the existing value in the Database... Code: [Select] // ******************** // Check for Answer. * // ******************** // Build query. $q1 = "SELECT response FROM bio_answer WHERE member_id=? AND question_id=?"; // Prepare statement. $stmt1 = mysqli_prepare($dbc, $q1); // Bind variable to query. mysqli_stmt_bind_param($stmt1, 'ii', $memberID, $questionID); // Execute query. mysqli_stmt_execute($stmt1); // Store results. mysqli_stmt_store_result($stmt1); // Check # of Records Returned. if (mysqli_stmt_num_rows($stmt1)==1){ // Answer Found. // Bind result-set to variable. mysqli_stmt_bind_result($stmt1, $currResponse); // Fetch record. mysqli_stmt_fetch($stmt1); So I guess I want to compare $answerArray[$questionID] against $currResponse and see if there are any differences?! What is the best way to do that? Any better ideas of how to check to see if the User made any changes to a field so I only do an UPDATE if there was actually a change? Thanks, Debbie How can i break down strings for example i have a simple search database for products where as a user searches a term this can be one, two three words and so on. I'm using a wildcard; but i want the best way to get the possible search so i would like to break down the string into separate words and then use that to search the database using wildcards is this possible? Thanks for reading. I've got a file with some strings that have both types of quotes in them. And I seem to have managed to get the data, display it in my html, store it in a js array (using a json_encode in php and then simply inserting it into my js) but I cannot seem to pass the string as a parameter form an onclick function call to js.
For most strings the addslashes makes it work in the function call. But for those with both sets of quotes it won't work. My console tells me there are "unterminated string constants..". I've experimented with many silly changes but none make it work.
Ex. of the strings:
What do you mean "It's crooked"?
Of course I could remove the contraction and that would probably work, but that would be a hack, would not it?
I am trying to make a little script that allows a user to search for blocks of text within strings. The user enters data into form fields and he or she can enter text into another form field (needle) to search the data fields (haystack). When the search string matches something in the data fields the associated data fields are highlighted in a yellow background color. Right now the search string is acting funny. When I enter a search string I get no highlighting unless if the first character(s) of the search string are the same as the first character(s) for the items. For instance, If I search for the text "at" in the word "bat" I will not get any yellow highlighting. But I would get highlighting for "bat" if I search for "ba." How would I change the code so that any data field is highlighted if the search string exists anywhere in the text for the data field? Also, I figured out how to stop the form fields from being yellow if they and the search field are empty/NULL, but I did this part in another file (as an IF statement) and can't seem to get it to work in the other file. How would I make it do the highlighting if and only if there is a search string in the search field (i. e. only highlighting when the search field is not NULL/empty). The code from my 2 files is here...: http://pastie.org/1095526 , http://pastie.org/1095528 Thanks very much to anyone who can help me. how do i limit this textfield to three strings? Code: [Select] <input type='text' size='40' name='search' style='font-size:16px; font-family:Arial;font-weight:bold;' /> is this php or javascript? i want only three strings to be allowed entered. Hmm, not quite sure how to do this one... If i have lots of strings saved in a mysql table and one was... "A man and a dog took a nice walk in the park" If a user then wanted to input another string into the table, but i wanted to check the new string was at least 5% different to all other in the table, how would i about doing this? Is it possible to do this via mysql, or would i have to pull out all the strings into a php array and process it that way... somehow? This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=316055.0 I have a php page which is ran after a form is posted from the previous page. I am having trouble getting the SQL strings to work. When the page is ran online there is no WSOD or error message but the tables in my database are not being updated. Any help with this would be greatly appreciated.
Attached Files
payment.php 1.79KB
4 downloads Hey Im trying to extract urls from inputted data so i can seperate it from the rest of the text but can't seem to work out what regex i need to use. The main issue is im trying to extract a specific domain example (google.com) But it could be written 4 ways (google.com, http://google.com, http://www.google.com, www.google.com). Does any one know how you do it ? Hi there, In my attached PHP script, I extract text between two strings in the input file and write the extracted text to an output file. Everything seems to work fine, except I can't figure out how to include the row that says "Richland" (after the row that says "Creighton") in the extracted text. If someone could guide me how to do this, I'd greatly appreciate it. The PHP script is attached. The input file is in htm format and I can't attach that here so I will provide a link to the file I'm calling: http://www.afws.net/data/pa/savedata/109/06/2009060920.pa.htm Many thanks!!! |