Jump to content

Error With My Mai() Function


snteran
 Share

Recommended Posts

I have not been able to figure what is wrong with my script. I was able to get it to work earlier and now I have added some additional stuff and the error occurs. I figure I would ask the pros.

 

><?php
//create short variable names
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$headline=$_POST['headline'];
$story_text=$_POST['story_text'];
 
$first_name = stripslashes($first_name); 
$last_name = stripslashes($last_name); 
$email = stripslashes($email); 

$toaddress = 'email@locshareholders.com';
$subject = 'Story from web site';
$mailcontent = 'First name: '.$first_name."\n"
      .'Last name: '.$last_email."\n"
                .'Guest email: '.$email."\n"
                .'Headline: '.$headline."\n"
Line ->19  .'Story Text: '.$story_text."\n";
$fromaddress = 'From: webserver@example.com';

mail($toaddress, $subject, $mailcontent, $fromaddress);
?>
<html>
<head>
 <title>Concerned Shareholders of L.O.C. - Submitted</title>
</head>
<body>
<h3>Your story has been sent.</h3>
<p>Thank your for you time.</p><br><br>
<a href="index.php" class="morelink">Home</a>

 

Error -

 

Parse error: parse error, unexpected '.' in /home/myvnyuol/public_html/submit_story.php on line 19

 

Thanks for the help.

Link to comment
Share on other sites

I am not home now so I can't try your code,

but may I suggest you change the complex part to use HEREDOC instead

to eliminate al the dots, quotes and new lines.

 

as an example

 

>$mailcontent = <<< HEREDOC
First name: $first_name
Last name: $last_email
Guest email: $email
Headline: $headline
Story Text: $story_text

HEREDOC;

 

 

be sure the last line has no space after the simicolon

Link to comment
Share on other sites

Thanks for the help Don,

 

I guess since I have never read any thing on the HEREDOC, I not sure what is going on. I added it to my code and still get an error. I'll try taking out the \n and see if that helps in my old code.

 

Thanks,

 

Sergio

 

www.locshareholders.com

 

BTW - on my site, the index page and the news page are in the same page, why is it that the header changes between those two pages. If you click on the news link and then click read more, you don't see a change, yet from the index - home page to index - news page there is a change on layout of header.php.

Link to comment
Share on other sites

>Line ->19  .'Story Text: '.$story_text."\n";

Tried removing "Line -> 19" from there? I am not quite sure about what it does. But it's on line 19 and that's where is says the error is coming from.

 

BTW - on my site, the index page and the news page are in the same page, why is it that the header changes between those two pages. If you click on the news link and then click read more, you don't see a change, yet from the index - home page to index - news page there is a change on layout of header.php.

Add valign="top" to the table tag you use for the content. Otherwise the default is to center the content in the middle of the table, and since your height is set to 100% it that means there will be white stuff at the top and bottom. :) It bugged me a long time before I figured it out!

Edited by D.Slatk
Link to comment
Share on other sites

Thanks for the suggestion of the valign ="top", unfortunetely I already had that in my <td> tag. The thing that is throwing me for a loop is that my index page is the same page for my home.php and news.php page. I am using a switch - case for the content section.

><tr>
    	 <td width="105px" valign="top"><?php include_once('common/left.php'); ?></td>
    	 <td valign="top">
	 <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
   <tr>
  	 <td width="5px" bgcolor='#996633'> </td>
  	 <td width="10px"> </td>
  	 <td valign="top"><br><br>
           <?php
           switch ($requestedPage) {
       case 'news':
      	 include('content/news.php');
      	 break;
       case 'ideas':
      	 include('content/submit.html');
      	 break;  
       default://home
      	 include('content/home.php');
      	 break;
    	 } 
    	 ?>
  	 </td>
  	 <td width="10px"> </td>
  	 <td width="5px" bgcolor='#996633'> </td>
   </tr>
	 </table>
 </td>
     <td width="20px"> </td>
   </tr>
   <tr>
 <td> </td>
    	 <td bgcolor='#996633'><?php include_once('common/footer.php'); ?></td>
 <td> </td>
   </tr>    

 

Not sure why on the new.php page it works fine but not in the home.php page.

 

thanks again,

 

Serge

Link to comment
Share on other sites

I tried your code and got the same error

I replace the $mailcontent part with my

$mailcontent = <<< HEREDOC

code and had no errors.

 

for more on HEREDOC see

heredoc primer

 

As to your home page and the news page

the diffeerence I see is the content is long enough to need scroll bars on the home page,

so I see a horizontal shift between them.

If you resize the browser window to bring the bottom edge up half way up the screen to force a scroll bar on all the pages

you will see no difference.

Link to comment
Share on other sites

Thanks for all the help. I got the mail to work, well the page does not error out. But I am not getting any emails from my testing. Not sure what is wrong. I tried the heredoc but I think I would like to tackle it this way first. I have an idea of the mail () function, I just can't seem to get it to work.

 

><?php
//create short variable names
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$headline=$_POST['headline'];
$story_text=$_POST['story_text'];
 
$first_name = stripslashes($first_name); 
$last_name = stripslashes($last_name); 
$email = stripslashes($email); 

{
$subject = "Topic for website"; 
$message = "Topic from $first_name, $last_name, $email"; 
$story_text = "$story_text";
    
   mail("snteran@hotmail.com", $subject, $message, $story_text, "From: MyWebSite<topic@locshareholders.com>nX-Mailer: PHP/" . phpversion()); 
   echo ''; 
} 
?>
<html>
<head>
 <title>Concerned Shareholders of L.O.C. - Submitted</title>
</head>
<body>
<h3>Your story has been sent.</h3>
<p>Thank your for you time.</p><br><br>
<a href="http://locshareholders.com/index.php" class="morelink">Home</a>


</body>
</html>

 

Thanks for the help,

 

Serge

Link to comment
Share on other sites

Thanks for the idea, I first added a print_r and it was printing the statement. Then I added the die and it died after the mail statement. so I altered my code and now my email is working. Yea! But it is not sending any real data.

 

><?php
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$headline=$_POST['headline'];
$story_text=$_POST['story_text'];
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

$recipient = 'snteran@hotmail.com';
$subject = 'Mail Test';
$message = '$first_name.$last_name.$email.$headline.$story_text';
   
$headers = 'From: snteran@hotmail.com'."\r\n"
         .'Reply-To: snteran@hotmail.com'."\r\n";

if (mail($recipient, $subject, $message, $headers)) {
       echo 'Mail Sent';
} else {
       echo 'Mail NOT Sent';
}
?>

 

The email is being sent, but I am getting "$first_name.$last_name.$email.$headline.$story_text" in my email. What do I have to do so the $_POST is added to each mail section?

 

Thanks,

 

Serge

Link to comment
Share on other sites

I will be adding some check functionality as soon as I get the email information correct. I add information to all my fields, but what I get in the email is just:

 

"$first_name.$last_name.$email.$headline.$story_text"

 

So, basically none of my post information is being entered. I must not be doing something right in my code. I don't know how to pass the information from the $_POST to my email. I need help with doing that part now.

 

Thanks,

 

Serge

Link to comment
Share on other sites

>$message = '$first_name.$last_name.$email.$headline.$story_text';

Variables are not evaluated when they are enclosed in single quotes as you them - the variable names are seen as just plain text. To have the variable names evaulated, you need to enclose the above string in double quotes (").

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...