Greenmachine Posted December 7, 2011 Share Posted December 7, 2011 Hi all, I am new to PHP and wish to use it simply to collect form data and email it to myself. From what I have gathered from PHP tutorials I have write the following script but I am getting syntax error warnings and cant figure out why. Can somebody please tell me where I am going wrong and if this script will actually work? The line I am getting errors on is <?php //message contains $message = "Name:$name</br>Email:$email</br>Phone:$phone</br>Preferred Date:$date</br>Best Time To Contact:$time"; ?> Thank you in advance. <body> <?php //my email $recipient = "info@hairlosslasergroup.co.uk"; //persons name $name = htmlspecialchars($_POST['name']); //persons email $email = htmlspecialchars($_POST['email']); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { die("E-mail address not valid"); } //persons phone number $phone = htmlspecialchars($_POST['phone']); //preferred date $date = htmlspecialchars($_POST['comments']); //best time $time = htmlspecialchars($_POST['time']); //check required fields $required = check_input($_POST['required'], "Please go back and complete all required fields"); //email subject $subject = ($_POST['subject'] //message contains $message = "Name:$name</br>Email:$email</br>Phone:$phone</br>Preferred Date:$date</br>Best Time To Contact:$time"; //message mail($recipient, $subject, $message); //redirect to thank you page header('Location:$redirect'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/252656-new-to-php-can-somebody-please-check-why-i-am-getting-syntax-errors/ Share on other sites More sharing options...
Greenmachine Posted December 7, 2011 Author Share Posted December 7, 2011 My form code is: <form id="form1" name="form1" method="post" action=""> <p>*required </p> <input name="redirect" type="hidden" value="thankyou.html" /> <input name="subject" type="hidden" value="HLLG consultation Kensington" /> <p>Name*</p> <input name="name" type="text" id="name" tabindex="10" size="20" maxlength="25" /> <p> </p> <p>Email*</p> <input name="email" type="text" id="email" tabindex="20" size="30" maxlength="50" /> <p> </p> <p>Phone*</p> <input name="phone" type="text" id="phone" tabindex="30" size="20" maxlength="20" /> <p> </p> <p>Preferred Date</p> <input name="date" type="text" id="date" value="dd/mm/yy" size="20" maxlength="10" /> <p> </p> <p>Best Time To Contact</p> <select name="time" id="time" tabindex="50"> <option value="morning" selected="selected">Morning</option> <option value="afternoon">Afternoon</option> <option value="evening">Evening</option> </select> <input name="required" type="hidden" id="required" value="name,email,phone" /> <input type="submit" name="submit" id="submit" value="Submit" tabindex="60" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/252656-new-to-php-can-somebody-please-check-why-i-am-getting-syntax-errors/#findComment-1295237 Share on other sites More sharing options...
QuickOldCar Posted December 7, 2011 Share Posted December 7, 2011 use this section of code here was your error //email subject $subject = ($_POST['subject'] <body> <?php //my email $recipient = "info@hairlosslasergroup.co.uk"; //persons name $name = htmlspecialchars($_POST['name']); //persons email $email = htmlspecialchars($_POST['email']); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { die("E-mail address not valid"); } //persons phone number $phone = htmlspecialchars($_POST['phone']); //preferred date $date = htmlspecialchars($_POST['comments']); //best time $time = htmlspecialchars($_POST['time']); //check required fields $required = check_input($_POST['required'], "Please go back and complete all required fields"); //email subject $subject = $_POST['subject']; //message contains $message = "Name:$name</br>Email:$email</br>Phone:$phone</br>Preferred Date:$date</br>Best Time To Contact:$time"; //message mail($recipient, $subject, $message); //redirect to thank you page header('Location:$redirect'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/252656-new-to-php-can-somebody-please-check-why-i-am-getting-syntax-errors/#findComment-1295243 Share on other sites More sharing options...
Greenmachine Posted December 7, 2011 Author Share Posted December 7, 2011 Thank you for the reply. Much help. Should of spotted that myself really. Sorry but I have a couple of newbie questions if you could help. If the php script is in its own .php file and just connect to the form by action, does it need to be enclosed in <body> tags and what file on the server does the .php file go into? the root folder /httpdocs or the php file. Thanks again for your help Quote Link to comment https://forums.phpfreaks.com/topic/252656-new-to-php-can-somebody-please-check-why-i-am-getting-syntax-errors/#findComment-1295254 Share on other sites More sharing options...
QuickOldCar Posted December 7, 2011 Share Posted December 7, 2011 properly formatted html is the best, the page would contain additional information in the head, but it will still run without doing so you can place the php file anywhere you want, as long as know where to link to it one example would be to create a folder named contact under root, and then name this file index.php now you would be able to visit the file as http://mysite.com/contact Quote Link to comment https://forums.phpfreaks.com/topic/252656-new-to-php-can-somebody-please-check-why-i-am-getting-syntax-errors/#findComment-1295261 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.