Solved

PHP passed variables in a message email string

Posted on 2004-03-28
6
176 Views
Last Modified: 2008-03-06
I'm new to php and have 90% of what I what working functioning.

What I've done is created a web page that is being emailed to different people based on the email address entered on the calling form.

On the posting form I'm collecting the sender name, recipient, recipient email address and a brief message.

On the called form, I'm putting it together into an email message as followes

<?php
<html>
<body>
$msg = '
/* Contents of webpage go here */
</body>
</html>
';

/* mailheader info goes here and sends out $msg to $recipent_name.

If the information between $msg ' through '; is just text and html, it goes through fine with all the normal formatting. (To save time, I create the page seperately, the copy the created page's html into the area between the ' ' . )

What I can't seem to do is have a location in the html (that gets emailed) have the value of $recepient_name and $message appear on the emailed web page. When I try it, all I get is the text '$recepient_name and $message. I've tried changing the $msg = ' to $msg = ", I've tried both type's of quotes around the variables but haven't been able to get the results I'm looking for.

Can someone point me in the right direction on this?

Thanks,

- Bill -
0
Comment
Question by:w_marquardt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 5

Expert Comment

by:winglis4
ID: 10700940
I do it like this - look at $name in the first line in particular:

$content = "Dear ".$name.",\n\n";
$content .= $bodycontent;
$content .= "\n\nThank you,\n\nThe Webmaster";
$content .= "\n\nIf you believe you have received this message in error,\nor wish to be removed from our email mailing list, please go to: http://site.com/unsubscribe.php?email=".$email.".";
mail($email, $subject, $content, $headers);

I think the 'dot' is what you are missing. You have to 'call' the variable outside of a string (outside the quotes), or you just get the variable name, not the value. The 'dot' adds the pieces together up til php sees the semicolon. Same thing with the .= which takes $content and adds the next line to it and makes that become $content.
0
 

Author Comment

by:w_marquardt
ID: 10700974
That approach works with the email. I've done it that way before. It doesn't work in this case. If you look back to the original posting, you'll see that everything that goes in the email is getting put into the $msg variable. I think there's something to the type of quotes I'm using but it made no difference using double quotes instead of single.

When I use the technique you outlined with in the $msg variable, I just get $content printed, not the text that has been strung together.

Thanks for the ideas but we're not quite there yet.

Regards,

- Bill -
0
 
LVL 5

Accepted Solution

by:
winglis4 earned 125 total points
ID: 10701050
I'll look more carefully at the original post...hang on....
I'm pretty sure you are going to have to do the string concatenation thing and break up the $msg variable to get the desired result - at least that's the way I know how to do it - I'm sure others know other ways :-)
$msg = "The first part and ";
$msg .= "the second part.";

If you are just putting the recipient's name in the greeting, it sould be just 2 lines.
$msg = "Dear ".$recipient_name.",\n";
$msg .= $message;

This should do it, if not, maybe you could cut and paste the section in question of your actual script - that usually helps, too.
Good luck,
Will
0
 

Author Comment

by:w_marquardt
ID: 10704196
Will,

I'll give that approach a try and see how it works out. Part of my problem is that this is an email invitation system so I'm trying to merge in a personal message into the web page content. So far, it's been more trouble that I expected.

I'll let you know how it turns out.

Regards,

- Bill -
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question