chriswhyte Posted August 12, 2011 Share Posted August 12, 2011 Hi all! I have a form at www.scott-jardine.com/ebook which I want to use for people to fill in to receive a free ebook. I'll then use the info to get in touch at a later date. So far I had it working so that I received an email with the form data and then I would manually email each person with a copy of the ebook. As I'm getting a lot of enquiries now, I don't want to spend all week replying to emails... so... I tried altering my php code to email the person and bcc me so that they get a link and I get the details I want... here's the code i'm using: <?php $field_name = $_POST['pname']; $field_email = $_POST['email']; $field_company = $_POST['company']; $field_jobtitle = $_POST['jobtitle']; $mail_to = $field_email; $bcc = '[email protected]'; $subject = 'Your FREE ebook is here!' $body_message = 'Thank you for visiting www.scott-jardine.com. You entered the following data to claim your FREE ebook:'"\n"; $body_message .= '--------------------'"\n"; $body_message .= 'From: '.$field_name."\n"; $body_message .= 'E-mail: '.$field_email."\n"; $body_message .= 'Company: '.$field_company."\n"; $body_message .= 'Job Title: '.$field_jobtitle;"\n"; $body_message .= '--------------------'"\n"; <?php print( '<a href="http://www.scott-jardine.com/CWHE/motivation.pdf">Click here to download your FREE ebook</a>' ); ?> $headers = 'From: [email protected]"\r\n"; $headers .= 'Reply-To: [email protected]'.$email."\r\n"; $headers .= 'Bcc: $bcc' . "\r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for your request. Your free e-book will be emailed to you shortly.'); window.location = 'ebook.htm'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('Message failed. Please, send an email to [email protected]'); window.location = 'ebook.htm'; </script> <?php } ?> But it doesn't seem to work as I get a syntax error. Any ideas? I'd really appreciate any help as I am a complete novice with php! Thanks Chris Quote Link to comment https://forums.phpfreaks.com/topic/244626-help-error-with-email-generated-from-form-submission/ Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 You are missing a semicolon after $subject = 'Your FREE ebook is here!' Quote Link to comment https://forums.phpfreaks.com/topic/244626-help-error-with-email-generated-from-form-submission/#findComment-1256442 Share on other sites More sharing options...
chriswhyte Posted August 12, 2011 Author Share Posted August 12, 2011 Okay, I put the semi-colon in and now it gives me the following error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/scottj/www/ebform.php on line 11 Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/244626-help-error-with-email-generated-from-form-submission/#findComment-1256445 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 You have already openeed php tags <?php in the start, and then inside these php tags u open again new ones <?php print( '<a href="http://www.scott-jardine.com/CWHE/motivation.pdf">Click here to download your FREE ebook</a>' ); Try to go through your code with a thought, and see this kind of easy syntax mistakes. I feel stupid that I need to find out every semicolon for you, since the script is already telling you the line numbers and everything where the error lies. Kinda feels like you don't even bother reading though your code, just come here and paste the next error and wait for answer. No offense. Edit: actually if you are using some simple txt editor that does not highlight the code for you it will be very easy to make mistakes like this. Get a editor with highlighting for php code. As you can see from the code that you pasted here in the forums inside code tags, it also shows you the syntax highlighting and as you can see your code breaks down and the PHP code shows as black in some places in the code. Quote Link to comment https://forums.phpfreaks.com/topic/244626-help-error-with-email-generated-from-form-submission/#findComment-1256449 Share on other sites More sharing options...
chriswhyte Posted August 12, 2011 Author Share Posted August 12, 2011 I hadn't used php code until yesterday! I was probably being kind to myself saying that I'm a novice... I really appreciate your help but I think I'm going to need it again as I really don't have a clue. I'm getting the same error and my code now looks like this: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/scottj/www/ebform.php on line 11 <?php $field_name = $_POST['pname']; $field_email = $_POST['email']; $field_company = $_POST['company']; $field_jobtitle = $_POST['jobtitle']; $mail_to = $field_email; $bcc = '[email protected]'; $subject = 'Your FREE ebook is here!'; $body_message = 'Thank you for visiting www.scott-jardine.com. You entered the following data to claim your FREE ebook:'"\n"; $body_message .= '--------------------'"\n"; $body_message .= 'From: '.$field_name."\n"; $body_message .= 'E-mail: '.$field_email."\n"; $body_message .= 'Company: '.$field_company."\n"; $body_message .= 'Job Title: '.$field_jobtitle;"\n"; $body_message .= '--------------------'"\n"; print( '<a href="http://www.scott-jardine.com/CWHE/motivation.pdf">Click here to download your FREE ebook</a>' ); $headers = 'From: [email protected]"\r\n"; $headers .= 'Reply-To: [email protected]'.$email."\r\n"; $headers .= 'Bcc: $bcc' . "\r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for your request. Your free e-book will be emailed to you shortly.'); window.location = 'ebook.htm'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('Message failed. Please, send an email to [email protected]'); window.location = 'ebook.htm'; </script> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244626-help-error-with-email-generated-from-form-submission/#findComment-1256452 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 You are missing a single quote in the end of this line $headers = 'From: [email protected]"\r\n"; should be $headers = 'From: [email protected]"\r\n"'; Quote Link to comment https://forums.phpfreaks.com/topic/244626-help-error-with-email-generated-from-form-submission/#findComment-1256453 Share on other sites More sharing options...
chriswhyte Posted August 12, 2011 Author Share Posted August 12, 2011 Really really sorry but it's just not working. I'm getting the same error on the same line. What else could be wrong? Is there any other way of writing it to get the same effect? Basically I just want the user to receive a link and me to receive their form data... Can it be done with the alert that should pop up after they click submit? <?php $field_name = $_POST['pname']; $field_email = $_POST['email']; $field_company = $_POST['company']; $field_jobtitle = $_POST['jobtitle']; $mail_to = $field_email; $bcc = '[email protected]'; $subject = 'Your FREE ebook is here!'; $body_message = 'Thank you for visiting www.scott-jardine.com. You entered the following data to claim your FREE ebook:'"\n"; $body_message .= '--------------------'"\n"; $body_message .= 'From: '.$field_name."\n"; $body_message .= 'E-mail: '.$field_email."\n"; $body_message .= 'Company: '.$field_company."\n"; $body_message .= 'Job Title: '.$field_jobtitle;"\n"; $body_message .= '--------------------'"\n"; print( '<a href="http://www.scott-jardine.com/CWHE/motivation.pdf">Click here to download your FREE ebook</a>' ); $headers = 'From: [email protected]'"\r\n"; $headers .= 'Reply-To: [email protected]'"\r\n"; $headers .= 'Bcc: $bcc' . "\r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for your request. Your free e-book will be emailed to you shortly.'); window.location = 'ebook.htm'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('Message failed. Please, send an email to [email protected]'); window.location = 'ebook.htm'; </script> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244626-help-error-with-email-generated-from-form-submission/#findComment-1256462 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 You have so messed up with single and double quotes in your strings, this should be working now <?php $field_name = $_POST['pname']; $field_email = $_POST['email']; $field_company = $_POST['company']; $field_jobtitle = $_POST['jobtitle']; $mail_to = $field_email; $bcc = '[email protected]'; $subject = 'Your FREE ebook is here!'; $body_message = "Thank you for visiting www.scott-jardine.com. You entered the following data to claim your FREE ebook:\n"; $body_message .= "--------------------\n"; $body_message .= "From: $field_name\n"; $body_message .= "E-mail: $field_email\n"; $body_message .= "Company: $field_company\n"; $body_message .= "Job Title: $field_jobtitle\n"; $body_message .= "--------------------\n"; print( '<a href="http://www.scott-jardine.com/CWHE/motivation.pdf">Click here to download your FREE ebook</a>' ); $headers = "From: [email protected]\r\n"; $headers .= "Reply-To: [email protected]\r\n"; $headers .= "Bcc: $bcc \r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for your request. Your free e-book will be emailed to you shortly.'); window.location = 'ebook.htm'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('Message failed. Please, send an email to [email protected]'); window.location = 'ebook.htm'; </script> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244626-help-error-with-email-generated-from-form-submission/#findComment-1256464 Share on other sites More sharing options...
chriswhyte Posted August 12, 2011 Author Share Posted August 12, 2011 Thank you so much for your help. You've really sorted me out! As soon as you'd fixed all the colons and semi-colons it started to make sense! I've even played around with the coding so that the file is displayed immediately rather than in an email so that only I get an email with the info I need! And it works!! Here's the code: <?php $field_name = $_POST['pname']; $field_email = $_POST['email']; $field_company = $_POST['company']; $field_jobtitle = $_POST['jobtitle']; $mail_to = '[email protected]'; $subject = 'Ebook downloaded!'; $body_message = "The following data was captured:\n"; $body_message .= "--------------------\n"; $body_message .= "From: $field_name\n"; $body_message .= "E-mail: $field_email\n"; $body_message .= "Company: $field_company\n"; $body_message .= "Job Title: $field_jobtitle\n"; $body_message .= "--------------------\n"; $body_message .= "This person downloaded the motivation ebook\n"; $headers = "From: $field_email\r\n"; $headers .= "Reply-To: $field_email\r\n"; $headers .= "Bcc: $bcc \r\n"; $mail_status = mail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for your request. Your free e-book will download shortly.'); window.location = '/CWHE/motivation.pdf'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('Message failed. Please, send an email to [email protected]'); window.location = 'index.htm'; </script> <?php } ?> Thanks again for all your help Quote Link to comment https://forums.phpfreaks.com/topic/244626-help-error-with-email-generated-from-form-submission/#findComment-1256483 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.