Jump to content

[SOLVED] Problems with email activation with embedded html text - HELP!!


barbs75

Recommended Posts

Hey guys,

 

Having a little problem with my script to send an email activation.

I have read some threads from this forum, which enabled me to devise html into my email message to send.

I think i have therefore done it all right, but when i run the script, i get a parse error as follows:

 

Parse error: syntax error, unexpected ';' in /homepages/43/d149598129/htdocs/go4home/register_process.php on line 142

 

This points the line code in my script as follows:

//email user confirmation of registration
$url       = 'http://www.mysite.co.uk/activate.php?user='.$encryptusername.'&hash='.$encryptpass;
$mysite    = 'www.mysite.co.uk';
$webmaster = 'Craig Barber website Manager';
$myemail   = '[email protected]';
    
$subject   = 'Please Activate your go4home account';
$message   = ?> <----------THIS IS THE LINE 142 WITH THE PARSE ERROR
<html>
    <style type="text/css">

 

It might even just be a coding error by myslef, but can anyone check my code below, and see where i might have gone wrong?

 

Here's my code, i have modified the script slightly to change the details of mysite for parts of the email content.

 

<?php
session_start();
//include database connection script
include('database.php');
//create error array to store errors
$errorcount = 0;
$errorarray = array();
$dataarray = array();

$username=$_POST['username'];

$encryptusername=md5($_POST['username']);

$title=$_POST['titleList'];

$surname=$_POST['surname'];

$forename=$_POST['forename']; //This value has to be the same as in the HTML form file

$email=$_POST['email']; //This value has to be the same as in the HTML form file

$encryptpass=md5($_POST['password']);

$encryptpass2=md5($_POST['password2']);

$password = $_POST['password'];

$membership=$_POST['membership'];

$consent1=$_POST['consent1'];

$consent2=$_POST['consent2'];

$termsConditions=$_POST['termsCond'];

//adding entered data into dataarray
$dataarray['username'] = $username;
$dataarray['surname'] = $surname;
$dataarray['forename'] = $forename;
$dataarray['email'] = $email;
$dataarray['membership'] = $membership;
//create session for data and store it
$_SESSION['data_storage']=$dataarray;

//checking for entry in all fields of form
if(!$username || !$surname || !$forename || !$email || !$encryptpass || !$encryptpass2 || !$membership){
$errorcount=1;
$errorarray['entries'] = "You didn't fill in a required field."; 
}

//checking entry in each field of form
if(!$username){
$errorarray['usernameEntry'] = "Please enter a username";
}

if(!$surname){
$errorarray['surnameEntry'] = "You are required to enter your surname";
}

if(!$forename){
$errorarray['forenameEntry'] = "You are required to enter your forename";
}

if(!$email){
$errorarray['emailEntry'] = "You are required to enter your email address";
}

if(!$password){
$errorarray['passwordEntry'] = "You are required to enter a password";
}

if(!$membership){
$errorarray['membershipEntry'] = "You are required to enter your membership";
}

//checking for existing users in database
$checkuser = mysql_query("SELECT username FROM customer WHERE username='$username'"); 

$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){
    unset($username);
$errorcount=1;
$errorarray['username'] = "The username you specified has already been taken. Please pick another one.";
    //exit();
}

//checking if passwords match
if ($encryptpass != $encryptpass2) {
$errorcount=1;
$errorarray['password'] = "Your passwords do not match, please re enter and try again";
//exit();
    }

//check that email is valid
  if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
  	if($email){
	$errorarray['email'] = "The email you have entered is not valid, please try again";
}
}



//checking username isn't over a certain character length
   $username = trim($username);
   if(strlen($username) > 12){
   	  $errorcount=1;
  $errorarray['usernamelength'] = "Your username is longer than 12 characters, please shorten it.";
   }	

//checking for acceptance of terms and conditions
if(!isset($termsConditions)){
$errorcount=1;
$errorarray['termsconditions'] = "Please read and accept our terms and conditions by ticking the appropriate box, thankyou"; 
}

//if there is an error, then output the error, store it in a session and exit program
//else carry on with registration and enter data into database table
if ($errorcount==1) {
        //echo $errorarray['entries'];
	//store session data for errors
	$_SESSION['error_storage']=$errorarray;
	//echo $_SESSION['error_storage'][0];
	//exit();
	include('register.php');
} else { 

$sql="INSERT INTO customer (username,encryptusername,title,surname,forename,email,encryptpass,password,membership,consent1,consent2) VALUES 		       ('$username','$encryptusername','$title','$surname','$forename','$email','$encryptpass','$password','$membership', '$consent1', '$consent2')"; 

if (!mysql_query($sql,$con)) {
 die('Error: ' . mysql_error()); 
} 
mysql_close($con);

//email user confirmation of registration
$url       = 'http://www.mysite.co.uk/activate.php?user='.$encryptusername.'&hash='.$encryptpass;
$mysite    = 'www.mysite.co.uk';
$webmaster = 'Craig Barber website Manager';
$myemail   = '[email protected]';
    
$subject   = 'Please Activate your go4home account';
$message   = ?>
<html>
    <style type="text/css">
<!--
p {
	padding:0 10px 0 10px;
}
.style1 {
	font-family: Century Gothic;
	font-size: 14px;
	font-weight:normal; 
	color: #00FF00; 
}
.style2 {
	font-family: Century Gothic;
	font-size: 14px;
	font-weight:normal;
	color:#174554;
}
.style3 {
	font-family: Century Gothic;
	font-size: 16px;
	font-weight:normal;
	color:#174554;	
}
-->
    </style>
<body bgcolor="#FFFFFF">
<center>
  <br>
  <br/>
        <div align="center" class="style2"><strong>Activation set-up for</strong><span class="style1"> <strong>$forename $surname</strong></span></div>
</center>
<br />
  <table width="800" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#174554">
    <tr>
      <td height="285" scope="col"><left><strong> </strong></left>
        <div align="left">
          <p>
          	<span class="style2">Hello</span><span class="style1"> $forename $surname,</span>
            <br/>
          	<span class="style2">
            	<br/>
                <span class="style3"><strong>Thankyou for registering with go4home!</strong></span>
                <br/><br/>
  				Your login details have been stored in our database as:<br/>
          		<strong>Username: $username<br/>
          		Password: $password</strong><br/><br />
           
			For security purposes and to fully activate your account please click on the link below:<br/>
			<a href="$url">activate account</a> and login to your account.<br/>
			<br/>
			If for any reason you cannot click on the above link, please copy and paste the following link into your web<br/>
			browser:
			<br/>
                url: $url<br/><br />
                
                Password: if you need to reset your password please use the 'Forgotten your password?' feature on the login <br />
                page.<br />
                By setting up a password and activating your account, you are agreeing to abide by the Terms of Use of the <br />
                go4home website<br/><br/>
                <strong>This E-mail address is not monitored. Please Do Not reply!</strong><br />
          		<br />
                Regards<br />
                The Go4home team
           </span>
          </p>
        </div>
      </td>
    </tr>
  </table>
</body>
</html>

<?php
$headers   = "From: $myemail\r\nReply-To: $myemail";
$headers  .= "Content-type: text/html\r\n";
    
$sent_mail = mail($email, $subject, $message, $headers);
//unset error storage session
unset($_SESSION['error_storage']);
include('register_success.php');
}
?>

 

Hopefully someone can help me!!

 

Cheers in advance

 

Craig

You're setting a variable equal to a closing tag.

 

Is it supposed to be blank? I ask that because you didn't give it a value like all the rest. If so, set it equal to an empty string.

$message = ''
?>

 

If you're trying to set it equal to the HTML below, use a different method like this to preserve HTML code. It will save you the trouble of having escape quotes.

$message  = <<<DELIMITER
<html>
...
</html>
DELIMITER;

$headers   = "From: $myemail\r\nReply-To: $myemail";
$headers  .= "Content-type: text/html\r\n";

Yo Charlieholder!

 

cheers for your help! although, i have tried what you suggested, using the

<<<DELIMITER
technique, and while the script executed this time, with no error, the email was shown in non-html, the code appeared rather that the output that i would like.

 

Am i missing something?

 

From my code, i took out the ending php in my variable

$message = ?>
to putting in:

//email user confirmation of registration
$url       = 'http://www.mysite.co.uk/activate.php?user='.$encryptusername.'&hash='.$encryptpass;
$mysite    = 'www.mysite.co.uk';
$webmaster = 'Craig Barber website Manager';
$myemail   = '[email protected]';
    
$subject   = 'Please Activate your go4home account';
$message   = <<<DELIMITER
<html>

//rest of content

</html>

DELIMITER;

$headers   = "From: $myemail\r\nReply-To: $myemail";
$headers  .= "Content-type: text/html\r\n";

 

Should this work?? and what is that the <<<DELIMITER thing does? i dont really understand what it is doing? you couldn't shed some light on this procedure could ya?

 

Cheers again

 

Craig

I apologize, but I'm going to have to politely bow out of this one. I looked at your code and everything looks perfect to me. I even use the same type of setup. I see nothing wrong with your code and have no idea what to even suggest to you.

 

Here's a snippet of code I use that does work. Maybe you will see something that I don't.

<?php
if (!$errors)
{
	$msg = <<<DELIMITER
<html>
<body>
<p>
<strong>Name:</strong><br />
$name
</p>
<p>
<strong>Email:</strong><br />
$email
</p>
<p>
<strong>Message:</strong><br />
$message
</p>
</body>
</html>
DELIMITER;
	$headers .= "From: " . $name . "<" . $email . ">\r\n";
	$headers .= "Content-type: text/html\r\n";
	$subject = "CH[DOT]COM - ".$subject;

	ini_set(sendmail_from, $email);
	$bool = mail($to, $subject, $msg, $headers);
	ini_restore(sendmail_from);

	if ($bool)
	{
		header("Location: /contact/thankyou.php");
		exit();
	} else
	{
		die("Something happened that wasn't supposed to.");
	}
}
?>

 

And after typing this out, the one thing I can suggest is to make sure whatever client you're using to actually read the email is setup to handle HTML emails. If it is, make sure the setting is enabled (as some let you choose).

Hey dude,

 

i got it working!! i decided that i didnt need the

Reply-To: $myemail
in there because i don't want them to reply anyway, and that was the only real difference between my code and your code!

 

Took it out, and he presto! it worked! sweet deal!!

 

Any ideas why that would have fixed?!?! would be good to know  :)

 

Also i had padding on my paragraph content in my stylesheet for my email....that hasn't worked. Does padding not work for email content or something??

 

cheers for your help, without your help, i probably wouldn't have got round to solving the problem!

 

oooo, if you didnt mind telling me, what does the

<<<DELIMITER
do? i'm guessing it allows some kind of embedding of content into a variable right?? i have tried researching this and reading in my books, but can't find any example of it or an explanation...

 

cheers mate,

 

Craig

You didn't have a \r\n between the Reply-To and the Content-type. You did have one after the From. So by eliminating the Reply-To, the \r\n after the from properly interrupted to make the Content-type work.That could be it.

 

Try adding your Reply-To back in and then \r\n after it.

 

If this thread is done, mark it SOLVED please.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.