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.
  • 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 The Helper:
    Happy Thursday!
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top