Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP email subject line

First timer here and I DID read the rules first. I also have burned hours searching for my answer to no avail. I think I am very close. I don't create php code yet, but I can modify existing code usually to fit my needs, most of the time, so that is where I am coming from.

The problem involves the subject line in my email module. Here is the code:

PHP:
$subject = "Repair log for ".$vehicleInfo[0]->year;' '.$vehicleInfo[0]->make;' '.$vehicleInfo[0]->model;' '.$vehicleInfo[0]->lic_plate;

When the email arrives the subject line reads the text and only one variable (year). I use the same code in the body of the email and it displays perfect, so the mechanics of the code appears to be fine. Is there a limit on characters in the subject line or is it something else?
any direction would be much appreciated!
I'll keep searching.........
 
The very first semicolon (the one after year) ends the assignment to $subject. Not sure what PHP does with the remainder of the line, but surely it does not end up in $subject. If you replace all semicolons (except the last one of course) by dots it will work:

PHP:
$subject = "Repair log for ".$vehicleInfo[0]->year.' '.$vehicleInfo[0]->make.' '.$vehicleInfo[0]->model.' '.$vehicleInfo[0]->lic_plate;

Quite an ugly construction though. I'm not a PHP buff but I think there may be better ways to format a string.
 
PHP:
$subject = "Repair log for {$vehicleInfo[0]->year}  {$vehicleInfo[0]->make}  {$vehicleInfo[0]->model}  {$vehicleInfo[0]->lic_plate}";
This also works. You'll have to admit it is a lot prettier 😁
 
You would not need the curly brackets if it were not for the -> operators. But you could do this:
PHP:
$year      = vehicleInfo[0]->year;
$make      = vehicleInfo[0]->make;
$model     = vehicleInfo[0]->model;
$lic_plate = vehicleInfo[0]->lic_plate;
$subject   = "Repair log for $year $make $model $lic_plate";
 

New Threads

Buy us a coffee!

Back
Top Bottom