PHP help - turning a variable into non-html text

konerboy

Run piggy Run!
Reaction score
95
hey guys i have a problem here i borrowed a email system from a tutorial but whenever i get the mails the text variables isn't converted so i basicly get a message, with the subject: message from $strname, with a message that reads: $straddress, is there anyone here that can make the subject be the actual name and make the mail contain the right comment?

Html if needed

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<title>Untitled Document</title>
</head>

<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" border="0" width="440">

<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="2" style="text-align:justify; line-height:15px;" class="body">

<form name="frm" method="POST" action="careersuccess2.php" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>

<td width="183px" height="23px" class="body">name</td></tr>
<tr>
<td width="74%"><input type="text" name="strname" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="224px" height="21px" class="body">comment</td></tr>
<tr>
<td width="74%"><textarea cols="16" name="straddress"></textfield></td>
</tr>
<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="Send" name="submit" onClick="return validate();"> <input type="reset" value="Reset" name="reset">
</td>
</tr>

</table>

</body>
</html>

Php

<?php

$strname=ucfirst($_REQUEST["strname"]);
$straddress=ucfirst($_REQUEST["straddress"]);
$strcity=ucfirst($_REQUEST["strcity"]);
$strstate=ucfirst($_REQUEST["strstate"]);

$stremail=$_REQUEST["stremail"];
$strcomments=ucfirst($_REQUEST["strcomments"]);







$message= '

$straddress.


';

// MAIL SUBJECT

$subject = " message from $strname ";

// TO MAIL ADDRESS


$to="[email protected]";

/*
// MAIL HEADERS

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: Name <[email protected]>\n";

*/



// MAIL HEADERS with attachment

$num = md5(time());

//Normal headers

$headers = "From: Name<[email protected]>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";

// This two steps to help avoid spam

$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";

// With message

$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";





// SEND MAIL

@mail($to, $subject, $message, $headers);

?>


can this be fixed or do i need MySql or w/e to do this?
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
Where did you learn php from? :rolleyes:

Code:
$subject = ' message from $strname ';

Should be

Code:
$subject = " message from $strname ";
or
$subject = " message from ".$strname;

Same for the others. Stop putting variables directly inside "". It's more comfortable, but it can lead to such problems.

. is a concatenation operator for strings. Put actual text inside "" and variables outside it.

Example:

Code:
echo "Hello " . $guest_name . "!";
 

enouwee

Non ex transverso sed deorsum
Reaction score
240
You have to validate the user input. Any user-provided data must not contain any linebreaks, otherwise your script will be used to spam whatever a malicious user gets paid for.

Otherwise, I'll submit a subject like " --- BUY VIAGRA NOW!!!\nTo: [long list of email addresses\n[my other mail content...]".

If you'd like to send email using PHP, use the PEAR packages Mail and Mail_Mime.

While we're at it, don't use $_REQUEST, but either $_GET or $_POST, whatever you're expecting in your form. It's much safer than a magic array that's a mix of cookie content and HTTP headers.
 

konerboy

Run piggy Run!
Reaction score
95
ok it worked now. now another thing.

how can i make the "stradress" and "strname" appear next to each other in the $message?

i've tried echo ad other things but they've just been giving trouble
 

UndeadDragon

Super Moderator
Reaction score
447
Code:
$message= $stradress . $strname;

might work.
 

SFilip

Gone but not forgotten
Reaction score
634
> it won't work
Why not?
 

JerseyFoo

1/g = g-1
Reaction score
40
It'll work, but it's silly imo for just a space.

Say a $var is = to "pie"

$str = 'I like ' . $var; I like pie
$str = "I like $var"; I like pie
$str = 'I like $var'; I like $var
 

Samuraid

Advisor
Reaction score
81
Embedding a variable in a double-quoted string is faster than concatenation, in terms of execution speed.

If you are worried about readability, just use braces {} around the variable:

PHP:
$food = 'Ice cream';
$str = "I think {$food} tastes great!"; // I think Ice cream tastes great!
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top