-
-
Am I doing this right? (Make contact form send copy of email to sender)
It's a lot simpler than it seems, all you would have to is extend the current $headers variable like so, all we're doing is adding one more line onto the headers variable: $headers = "From: $myemail\n"; $headers .= "Content-type:text/html; charset=UTF-8\n"; $headers .= "Reply-To: $email_address"; $headers .= "\nCC: $email_address"; If you want to add a checkbox; then add the following to your contact form (change it to suit your needs etc): <label for="send_to_user">CC?</label> <input type="checkbox" value="1" name="send_to_user" id="send_to_user" /> Add this to the top of your contact form file, what this code is doing is checking if in the post array there is a key called 'send_to_user'. If the checkbox has not been ticked, this will not be sent over. When type-casted, 1 will return as true and 0 will return false, so it's just a quick check to make sure the value is correct. $sendToUser = array_key_exists('send_to_user', $_POST) && (bool)$_POST['send_to_user']; Then change your $headers variable to look like so, if the checkbox has been selected, we'll just append the cc onto the string: $headers = "From: $myemail\n"; $headers .= "Content-type:text/html; charset=UTF-8\n"; $headers .= "Reply-To: $email_address"; if ($sendToUser) { $headers .= "\nCC: $email_address"; } Your overall file at the end should look something like this: <?php $sendToUser = array_key_exists('send_to_user', $_POST) && (bool)$_POST['send_to_user']; $errors = ''; $myemail = 'EMAIL@EMAIL.COM'; if (empty($_POST['contactname']) || empty($_POST['email']) || empty($_POST['message']) ) { $errors .= "\n Error: all fields are required"; } $name = $_POST['contactname']; $email_address = $_POST['email']; $message = $_POST['message']; if (!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i', $email_address)) { $errors .= "\n Error: Invalid email address"; } if (empty($errors)) { $to = $myemail; $email_subject = "You have a new message"; $email_body = "(html based email here)"; $headers = "From: $myemail\n"; $headers .= "Content-type:text/html; charset=UTF-8\n"; $headers .= "Reply-To: $email_address"; if ($sendToUser) { $headers .= "\nCC: $email_address"; } mail($to, $email_subject, $email_body, $headers); //redirect to the 'thank you' page header('Location: /thanks/'); } ?> <!doctype html> <html> <head> <title>Contact form handler</title> </head> <body> <!-- This page is displayed only if there is some error --> <?php echo nl2br($errors); ?> </body> </html>
-
-
-
My Web Development Arsenal
Operating System: Linux Ubuntu / Windows 7 (for when access to Fireworks / Photoshop is needed) I have 2 machines I develop on, a laptop which I got back in the day and a PC I built myself. PHPStorm Terminal; (Node, SASS, Git, Grunt) etc Vagrant (create a VM which runs as a server, can customise the setup to different PHP versions, etc) - quite resource hungry, so only used on Desktop XAMPP Fireworks / Photoshop
-
Reading associative arrays?
In answering the title of your thread, the best way I've found to read arrays is using the function print_r();: <?php $array_var = array(); // the var which stores the array ?> <pre><?php print_r($array_var); ?></pre> This will output the array in an easy-to-read format, where all the keys you need to access the array items are defined. For this array: <?php $new_invoice = array( array( "Type"=>"ACCREC", "Contact" => array( "Name" => "Income" ), "Date" => "2013-12-31", "DueDate" => "2013-12-31", "Status" => "DRAFT", "LineAmountTypes" => "Exclusive", "LineItems"=> array( "LineItem" => array( array( "Description" => "Sales - Wet", "Quantity" => "1.0000", "UnitAmount" => "2500.00", "AccountCode" => "200" ), array( "Description" => "Sales - Pool Table", "Quantity" => "1.0000", "UnitAmount" => "325.25", "AccountCode" => "200" ) ) ) ) ); ?> <pre><?php print_r($new_invoice); ?></pre> The following is outputted in the HTML: Array ( [0] => Array ( [Type] => ACCREC [Contact] => Array ( [Name] => Income ) [Date] => 2013-12-31 [DueDate] => 2013-12-31 [Status] => DRAFT [LineAmountTypes] => Exclusive [LineItems] => Array ( [LineItem] => Array ( [0] => Array ( [Description] => Sales - Wet [Quantity] => 1.0000 [UnitAmount] => 2500.00 [AccountCode] => 200 ) [1] => Array ( [Description] => Sales - Pool Table [Quantity] => 1.0000 [UnitAmount] => 325.25 [AccountCode] => 200 ) ) ) ) ) As you can see all of your information is stored in the 0 array key: $new_invoice[0] Instead of: $new_invoice So to access your description you will need to do the following: $new_invoice[0]['LineItems']['LineItem'][0]['Description']; // first line item $new_invoice[0]['LineItems']['LineItem'][1]['Description']; // second line item To add new items into your "LineItem" key, use the following code: $new_invoice[0]['LineItems']['LineItem'][] = array( "Description" => "", "Quantity" => "", "UnitAmount" => "", "AccountCode" => ""); To loop through the "LineItems" section, using a foreach like so would be plausable: <?php foreach($new_invoice[0]['LineItems']['LineItem'] as $lineItem) { $lineItem['Description']; // this is the description of the line item being looped $lineItem['Quantity']; // this is the quantity of the line item being looped $lineItem['UnitAmount']; // so on and so forth $lineItem['AccountCode']; } ?> I hope you've found this useful.
-
-
Yakindo reacted to a post in a topic:
Which is the best php frame work for developing a large scale professional network like linkedin or xing?
-
Contact Script help
<?php $name = $_POST['name']; $email = $_POST['email']; $number = $_POST['number']; $message = $_POST['message']; $formcontent="From: $name, \n Number: $number, \n Message: $message"; $recipient = ""; $subject = "Contact Form"; $mailheader = "From: $email \r\n"; if( mail($recipient, $subject, $formcontent, $mailheader) ) { header("Location: thankyou.html"); // success } else { // errors } ?> Add some validation checks!
-
-
-
-
- Does WDF arrange any functions for members to meet up?
-
Please Help with WHERE clause
Right for that function, all you need to do is pass through the category and the sub id, not an array of data. Just two variables (or pieces of data). <?php function get_item_for_sub($sel_sub, $sel_cat) { $query = "SELECT * FROM stock WHERE position = " . $sel_cat . " AND sub_pos = " . $sel_sub . ""; $item_set = mysql_query($query); confirm_query($item_set); return $item_set; } $idkRandomVar = get_item_for_sub($sel_sub['id'], $sel_cat['id']); ?> Then all you need to do is loop through data which has been returned, I don't know if this is any help, could you provide more code (obviously take out any sensitive information)
-
-
-
Please Help with WHERE clause
If you're going to be building a big website, you want to be testing your queries before you implement them into PHP code. Try testing your query first with MySQL Workbench. It allows you to connect to a DB and test your queries before you put it into code. This is great for getting the exact data you want from your query, reducing load times etc. Where is your function getting these two array items from? $query .= " WHERE position = {$sel_catergorie['Id']} "; $query .= " AND sub_pos = {$sel_sub['Id']}"; Also, concatenating your variables being used in the query like so: $query = "SELECT * FROM stock WHERE position = " . $sel_catergorie['Id'] . " AND sub_pos = " . $sel_sub['Id'] . ""; Have you got the spelling correct of your variables etc?
-
-
How Do I Set Space Between Lines Of Sentences In Dreamweaver?
Line height changes the space between each line of your paragraph, it's used for readability of your content
-
How Do I Set Space Between Lines Of Sentences In Dreamweaver?
p { margin: 0 0 15px; /* adds a margin of 15px to the bottom of the paragraph */ line-height: 1.5em /* will increase the line-height of your paragraph */ } In your CSS you need to modify the styling of your <p> tags, I hope this helps! Just realised you're in Dreamweaver, go to code view and at the top of the document, find (I doubt you've got an external stylesheet). <style type="text/css"> /* code here */ </style> Now replace /* code here */ with the previous bit of code I posted.
- Website share button
-
cant get my head around a query
My advice would be to get MySQL Workbench, it'll allow you to test your queries before you deploy them.
-
Light or Dark Website Designs?
Light, clean designs are my favourite. It really depends on the context of the website.
-
Hermes reacted to a post in a topic:
Adding to an existing Php script to allow more fields to be added to a contact form
-
Adding to an existing Php script to allow more fields to be added to a contact form
<p class="institution"> <select name="institution" id="Institution"> <option selected disabled>Please choose your status</option> <option value="Private Client">Private client</option> <option value="Institutional Client">Institutional client</option> </select> You add values to the select options, otherwise the PHP $_POST["institution"] won't contain any information, since there aren't any values
-
How would you improve this design?
Can you expand on this? easter egg
-
Want to become a web designer
Self-taught, started when I was around 14 - went to college, left after 6 months because I knew what I wanted to do, be a website developer and there was a web development apprenticeship open, I applied and got it. Got my apprenticeship qualification and now I'm in University, and doing work experience wherever possible. University is just the same as studying on your own, only you get a briefing of assignments to create and pay £9,000 a year... aha. Go for a degree, get work experience and build up your portfolio. That way you're ahead of the majority of website developers who come out of University, because they tend to have no work experience or an online presence from what I've witnessed. Read as many books as possible, as it teaches you a more efficient way of coding, as well as areas of a language that you might find useful, especially O'Reilly books, read up on: Web Designer: UX Design (Anything by Jakob Nielsen) HTML, CSS, Javascript (O'Reilly Books, codeacademy, W3Fools (for the basics) ) Photoshop / Fireworks (clicky) Web Developer: Server-side Programming ( PHP, Ruby, ASP ) ( O'Reilly Books, codeacademy, W3Fools ) HTML, CSS, Javascript (O'Reilly Books, codeacademy, W3Fools (for the basics) ) Don't go straight for learning them all at once, it'll be quite overwhelming. It depends what route you want to go down.