• 0

Simple PHP Syntax Help


Question

Hello,

Im trying to get these mail headers right, and i just cant figure it out. I guess it doesnt help that, despit my googling, i cant get a good explanation of what the single quote makrs (') and dot (.) do, anyway, i have:

$headers .= 'Reply-To: '.$title.$firstName.$lastName.' <'.$email.'>' . "\r\n";
$headers .= 'Return-Path: '.$name.' <'.$email.'>' . "\r\n";
$headers .= 'X-Mailer: PHP/'.phpversion().'' . "\r\n";
$headers .= 'X-Sender: '.$emailRecipient.'' . "\r\n";

I want it to show:

Reply-To: Mr. Joe Bloggs <[email protected]>

But i just cant get it right.

Any help would be much appreciated.

Cheers

Link to comment
https://www.neowin.net/forum/topic/860322-simple-php-syntax-help/
Share on other sites

10 answers to this question

Recommended Posts

  • 0

the .' and '. are the separation markers for the code, so it knows when you are using PHP and when you aren't.

Are you good with PHP? Because those are simply just headers, and not the actual mail() class, which sends the email.

  • 0

Thanks for the reply.

I wouldnt say im good, but i would like to think i have a semi passable acquatinance! Im aware these are just the headers, ive got my mail function working, its just the reply-to field isnt showing up as i want in the email client.

Im confused though, are you saying it should be:

.'$var'.

Whereas im using:

'.$var.'

Im guessing that makes a difference?

Cheers

EDIT:

OK, can you explain why:

$headers .= 'Reply-To: '.$title.' '.$firstName.' '.$lastName.' &lt;'.$email.'&gt;' . "\r\n";

Shows as:

reply-to "Mr. Joe Bloggs" <[email protected]>

Where so the extra double quote marks come from? They arent there in the from field, ie in gmail

from Mr. Test Sender <[email protected]>

Edited by Bollard
  • 0

the correct way would be '.$var.'

try to add a From: into your header:

$headers .= 'From: '.$YOUREMAILVARIABLE. "\r\n";
$headers .= 'Reply-To: '.$title.$firstName.$lastName.' &lt;'.$email.'&gt;' . "\r\n";
$headers .= 'Return-Path: '.$name.' &lt;'.$email.'&gt;' . "\r\n";
$headers .= 'X-Mailer: PHP/'.phpversion().'' . "\r\n";
$headers .= 'X-Sender: '.$emailRecipient.'' . "\r\n";

  • 0

To be honest, you really don't need all those single quotes.. you can simplify that code.

$headers .= 'To: $FirstName &lt;$Email&gt;' . "\r\n";
$headers .= 'From: $FromName &lt;$YourEmail&gt;' . "\r\n";
$headers .= 'Reply-To:$ReplyTo &lt;$replytoEmail&gt;'. "\r\n";

You can keep the rest of the headers, but perhaps just change those two lines

  • 0

My current headers are:

$headers .= 'From: Company &lt;'.$emailRecipient.'&gt;' . "\r\n";
$headers .= 'Reply-To: '.$title.' '.$firstName.' '.$lastName.' &lt;'.$email.'&gt;' . "\r\n";
$headers .= 'Return-Path: '.$title.' '.$firstName.' '.$lastName.' &lt;'.$email.'&gt;' . "\r\n";
$headers .= 'X-Mailer: PHP/'.phpversion().'' . "\r\n";
$headers .= 'X-Sender: '.$emailRecipient.'' . "\r\n";

In GMail this shows up as:

from Company <[email protected]>

reply-to "Mr. Joe Bloggs" <[email protected]>

to Company Sales <[email protected]>

date 30 December 2009 02:50

subject Enquiry for Company

I dont understand where the quote marks around the repl-to name are coming from?

  • 0

umm, depends how the application is used. If you are using it as a contact form, sure it could be an option, but I wouldn't include it.

You would just need to loop it (obviously changing the send-to email to the senders email). Wouldn't take long to include at all.

  • 0
To be honest, you really don't need all those single quotes.. you can simplify that code.

$headers .= 'To: $FirstName &lt;$Email&gt;' . "\r\n";
$headers .= 'From: $FromName &lt;$YourEmail&gt;' . "\r\n";
$headers .= 'Reply-To:$ReplyTo &lt;$replytoEmail&gt;'. "\r\n";

You can keep the rest of the headers, but perhaps just change those two lines

$variables aren't evaluated in single quotes, but they are in double quotes:

$headers .= "To: $FirstName &lt;$Email&gt;\r\n";
$headers .= "From: $FromName &lt;$YourEmail&gt;\r\n";
$headers .= "Reply-To:$ReplyTo &lt;$replytoEmail&gt;\r\n";

  • 0

For further clarification, the dots are concatenation symbols in PHP. It joins things together. Much like + does in languages like C#. It's just like "Test" + "Bob" (C#), but PHP uses "Test" . "Bob". Single quotes enclose a string, just as double quotes do and, as mentioned earlier, variables are not evaluated within single quotes, unless they are concatenated with the string or strings.

Steven

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Hello, It would appear so, according to https://finance.yahoo.com/news/how-to-hide-your-home-on-google-maps-apple-maps-204146687.html. Regards, Aryeh Goretsky      
    • Hello, The Nvidia Founders Edition 3080 video card is approximately six years old, correct? Have you looked into whether replacement fans are available for it? Perhaps replacing those will improve cooling, especially when combined with cleaning the card's heatsink and replacing the thermal interface materials. Regards, Aryeh Goretsky  
    • Hello, While ~104 GB of space may seem generous (at least compared to other e-readers which have 8-32GB), I feel at this price point the device should have a Micro SDXC card slot for expansion, particularly if it allows audio books to be installed and played. I hope to see more reviews of 6" phone-sized e-readers on Neowin in the future. It will be interesting to see how they compare. Regards, Aryeh Goretsky
    • Sandboxie Plus 1.17.8 / Classic 5.72.8 by Razvan Serea Run programs in a sandbox to prevent malware from making permanent changes to your PC. Sandboxie allows you to run your browser, or any other program, so that all changes that result from the usage are kept in a sandbox environment, which can then be deleted later. Sandboxie is a sandbox-based isolation software for 32- and 64-bit Windows NT-based operating systems. It is being developed by David Xanatos since it became open source, before that it was developed by Sophos (which acquired it from Invincea, which acquired it earlier from the original author Ronen Tzur). It creates a sandbox-like isolated operating environment in which applications can be run or installed without permanently modifying the local or mapped drive. An isolated virtual environment allows controlled testing of untrusted programs and web surfing. Sandboxie is available in two flavors Plus and Classic. Both have the same core components, this means they have the same level of security and compatibility. What's different is the user interface the Plus build has a modern Qt based UI which supports all new features that have been added since the project went open source. The Classic build has the old no longer developed MFC based UI, hence it lacks support for modern features, these features can however still be used when manually configured in the Sandboxie.ini. Sandboxie Plus 1.17.8 / Classic 5.72.8 release notes: Added added DisableCustomTitleOpt=[process,][y|n] to allow [#] sandboxie title markers on custom-titlebar windows (Delphi VCL, Qt, Electron) that were previously skipped to prevent DWM repaint CPU loops #5387 Changed updated bundled ImDisk driver to 3.0.2 #5419 Fixed fix Suppress logs for expected non-user SIDs #5422 SbieSvc.exe: SBIE2218/2219 error when run program as administrator #5417 fixed explorer.exe crashes in Application Compartment when Huorong Security is installed #5423 Download: Sandboxie Plus (64-bit) | 23.5 MB (Open Source) Download: Sandboxie Classic (64-bit) | 3.0 MB Links: Sandboxie Website | GitHub | ARM64 | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Hello, Christian Maas' XVI32 is a nice (and very small) hex editor. Speaking of hex editors, many years ago a colleague and I who both worked at Tribal Voice managed to edit a copy of the company's PowWow instant messaging client to make it behave better now that all of its lookup servers and other server-side tech was gone.  The program didn't support NAT (RFC-3022 was introduced in January 2001, the same time Tribal Voice was shuttered), but it still worked okay if you manually set up port-forwarding on your router.  The server at http://powwow.jazy.net/ hosts a copy (usual warnings about downloading and running untrusted code from random internet servers apply). I occasionally use some tools like Funduc Software's Search and Replace and Application Mover when I need to make mass-edits to text-based files or move programs with a hard-coded installation directories, respectively.  When I need to figure out the exact LCD panel inside of a laptop, EnTech Taiwan's Monitor Asset Manager is my go-to tool for that purpose. JD Design's website (now hosted on github.io) has a number of interesting freeware and shareware utilities.  I used to use their TouchPro utility to set the file timestamps on software I was mastering to match its version number (e.g., version 3.00 of a program had all of its files dates set to 3:00AM, and so forth). Karenware has a number of interesting freeware utilities, too. Regards, Aryeh Goretsky  
  • Recent Achievements

    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
    • One Month Later
      Leroy Jethro Gibbs earned a badge
      One Month Later
    • Conversation Starter
      flexorcist earned a badge
      Conversation Starter
    • One Month Later
      AndreaB earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      509
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      138
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      82
  • Tell a friend

    Love Neowin? Tell a friend!