Jump to content

Help! Error with email generated from form submission.


chriswhyte

Recommended Posts

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 = 'chris.whyte@scott-jardine.com';
$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: chris.whyte@scott-jardine.com"\r\n";
$headers .= 'Reply-To: chris.whyte@scott-jardine.com'.$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 chris.whyte@scott-jardine.com');
	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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 = 'chris.whyte@scott-jardine.com';
$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: chris.whyte@scott-jardine.com"\r\n";
$headers .= 'Reply-To: chris.whyte@scott-jardine.com'.$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 chris.whyte@scott-jardine.com');
	window.location = 'ebook.htm';
</script>
<?php
}
?>

Link to comment
Share on other sites

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 = 'chris.whyte@scott-jardine.com';
$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: chris.whyte@scott-jardine.com'"\r\n";
$headers .= 'Reply-To: chris.whyte@scott-jardine.com'"\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 chris.whyte@scott-jardine.com');
	window.location = 'ebook.htm';
</script>
<?php
}
?>

Link to comment
Share on other sites

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 = 'chris.whyte@scott-jardine.com';
$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: chris.whyte@scott-jardine.com\r\n";
$headers .= "Reply-To: chris.whyte@scott-jardine.com\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 chris.whyte@scott-jardine.com');
	window.location = 'ebook.htm';
</script>
<?php
}
?>

Link to comment
Share on other sites

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 = 'chris.whyte@scott-jardine.com';
$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 chris.whyte@scott-jardine.com');
	window.location = 'index.htm';
</script>
<?php
}
?>

 

Thanks again for all your help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.