Avatar of w_marquardt
w_marquardtFlag for United States of America

asked on 

PHP passed variables in a message email string

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 -
PHP

Avatar of undefined
Last Comment
w_marquardt
Avatar of winglis4
winglis4

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.
Avatar of w_marquardt
w_marquardt
Flag of United States of America image

ASKER

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 -
ASKER CERTIFIED SOLUTION
Avatar of winglis4
winglis4

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of w_marquardt
w_marquardt
Flag of United States of America image

ASKER

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 -
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo