vincewentwrong Posted March 7, 2013 Share Posted March 7, 2013 Hi there, I've been following a great tutorial on youtube which has helped my understand a lot of what's going on in PHP forms but I cannot for the life of me get it to work properly.I've tested it online, it sends to my email address but it's either completely blank or comes up with the title of a single field. I've tried playing around with some variations a lot so it probably makes less sense than it did before.Can anyone help me? I'd really like to know where I'm going wrong and my brain hurts now!<?php$to = 'MYEMAILADDRESS (Yes I know, I've taken it out)';$subject = 'Enquiry';$model = $_POST['model'];$year = $_POST['year'];$info = $_POST['info'];$image = $_POST['image'];$name = $_POST['name'];$location = $_POST['location'];$number = $_POST['number'];$email = $_POST['email'];$message = <<<EMAIL$model$year$info$image$name$location$number$emailEMAIL;$header = '$model';if($_POST){ mail($to, $model, $year, $info, $image, $name, $location, $number,$email); $feedback = 'Thanks, we will get back to you shortly.';}?><div id="form"><p id="feedback"><?php echo $feedback; ?></p><form action="?" method="post"><ul><li> <label for="model"> System Brand / Model:</label> <input type="text" name="model" id="model" /> </li> <li> <label for="year">Year Of Manufacturer:<br />(If Known)</label> <input type="text" name="year" id="year" /> </li> <li> <label for="info">Additional Information:</label> <textarea name="info" id="info"></textarea> </li> <li> <label for="image">Upload an Image:</label> <input name="image" type="file" id="image" /> </li> <li> <label for="name"> Clinic Name:</label> <input type="text" name="name" id="name" /> </li><li> <label for="location">Location:</label> <input type="text" name="location" id="location" /> </li><li> <label for="number">Contact Number:</label> <input type="text" name="number" id="number" /> </li> <li> <label for="email">Email Address:</label> <input type="text" name="email" id="email" /> </li></ul><input type="submit" name="submit" value="Send" /></form></div> Thanks! Quote Link to comment Share on other sites More sharing options...
Manixat Posted March 7, 2013 Share Posted March 7, 2013 I can't understand this part $message = <<<EMAIL $model $year $info $image $name $location $number $email EMAIL; $header = '$model'; what are you trying to do?In case you want to add all those variables into the message variable you need to use dots to connect them or just double quotes around the whole thing. Same story with $header = '$model'; This will set the $header value to the text $model. if you want to set it to be equal to the model variable you need to either use double quotes or no quotes at all. Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 7, 2013 Share Posted March 7, 2013 If you don't understand it, probably best to learn about it instead of saying its wrong. That's HEREDOC syntax. I can't understand this part $message = <<<EMAIL $model $year $info $image $name $location $number $email EMAIL; $header = '$model'; what are you trying to do? In case you want to add all those variables into the message variable you need to use dots to connect them or just double quotes around the whole thing. Same story with $header = '$model'; This will set the $header value to the text $model. if you want to set it to be equal to the model variable you need to either use double quotes or no quotes at all. Quote Link to comment Share on other sites More sharing options...
Manixat Posted March 7, 2013 Share Posted March 7, 2013 If you don't understand it, probably best to learn about it instead of saying its wrong. That's HEREDOC syntax. My apologies. Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 7, 2013 Share Posted March 7, 2013 (edited) OP: mail accepts specific arguments that you are not supplying. Read that and fix mail() Also single quoted strings will not have variables parsed. '$model' is the literal string of '$model'. You go through the trouble of creating $message but never use it. Edit: YAY MOBILE EDIT FINALLY. Edited March 7, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
vincewentwrong Posted March 7, 2013 Author Share Posted March 7, 2013 Ok I'll read that, I've got a habit of not reading anything and frying my brain trying to work it out with trial and error! Thanks. Quote Link to comment Share on other sites More sharing options...
vincewentwrong Posted March 7, 2013 Author Share Posted March 7, 2013 Oh so it requires to, subject and message... Am I going to put my ....... $model$year$info$image$name$location$number$email ....after message? Quote Link to comment Share on other sites More sharing options...
vincewentwrong Posted March 7, 2013 Author Share Posted March 7, 2013 Ok... Progress! I'm now getting $model$year$info$image$name$location$number$email ... I just need to find out how to send whats in the fields instead of the names of them Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 7, 2013 Share Posted March 7, 2013 Post your new code Quote Link to comment Share on other sites More sharing options...
vincewentwrong Posted March 8, 2013 Author Share Posted March 8, 2013 <?php$to = 'nick@photronics.co.uk';$subject = 'Sales Enquiry';$model = $_POST['model'];$year = $_POST['year'];$info = $_POST['info'];$image = $_POST['image'];$name = $_POST['name'];$location = $_POST['location'];$number = $_POST['number'];$email = $_POST['email'];$message = <<<EMAIL$model$year$info$image$name$location$number$emailEMAIL;$message = '$model,$year,$info,$image,$name,$location,$number,$email';if($_POST){ mail($to, $subject, $message, $header); $feedback = 'Thanks, your quote is one its way.';}?> Quote Link to comment Share on other sites More sharing options...
vincewentwrong Posted March 8, 2013 Author Share Posted March 8, 2013 Sorry I took my time, I went home yesterday.... Quote Link to comment Share on other sites More sharing options...
vincewentwrong Posted March 8, 2013 Author Share Posted March 8, 2013 Changed $_Post to $_REQUEST and it seems to work a bit better now...... I don't understand the tutorial at all, I learn better hands on! Quote Link to comment Share on other sites More sharing options...
Barand Posted March 8, 2013 Share Posted March 8, 2013 Jessica told you that variables inside a single quoted string don't get expanded, so why do you re-create $message using single quotes having just created it correctly using heredoc syntax? Quote Link to comment Share on other sites More sharing options...
vincewentwrong Posted March 8, 2013 Author Share Posted March 8, 2013 I have no idea... I copied a tutorial! Someone has advised me that there isn't any security on it so I might have to pay somebody to help me after all Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 You're not actually learning anything by copying and pasting and not knowing what it does. Look up the syntax in the manual, and read the manual. Look for Strings first. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.