• 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

    • Affinity by Canva 3.2.2.4557 by Razvan Serea Affinity by Canva is a free, all-in-one creative app combining vector design, photo editing, and page layout in a single platform. Originally developed by Serif, it’s now under Canva, offering professional-grade tools without subscriptions. Users get full access to Pixel, Vector, and Layout studios, plus ongoing updates. Designed for Mac and Windows, it empowers designers, illustrators, and content creators to work faster, smarter, and more creatively than ever before. Affinity is a unified, high-performance design platform combining vector, raster, and layout workflows. It offers fully non-destructive editing, advanced curve and shape manipulation, artboards, symbols, and seamless integration of pixel and vector content. The photo engine supports RAW editing, compositing, retouching, and batch processing with macro automation. Layout tools include long-form document support, typographic precision, navigational elements, CMYK-ready print, and Data Merge. Canva AI Studio adds generative tools (Fill, Expand, Edit), Depth Map, Super Resolution, and advanced portrait effects, accessible via Canva Pro or higher. Broad file compatibility and customizable workspaces ensure professional-grade efficiency. Advanced AI features like Generative Fill and Expand are unlocked in Affinity through the Canva AI Studio for users with a Canva premium plan (Pro, Business, Enterprise, or Education). Affinity is truly free. Every tool in the Pixel, Vector, and Layout studios is fully accessible, along with all customization and export options—no limits, no payments required. The app also receives free updates with new features and improvements. Your creativity remains yours. Affinity stores all your work locally on your device. Canva does not use any Affinity content to train AI or develop features, including anything created with Canva AI tools within Affinity. If you export or upload your work to Canva, you remain in full control. Data preferences can be reviewed or updated at any time in your Canva account settings. Why is Affinity free? Curious how this is possible? Here’s the philosophy behind it and how it works. Note: A free Canva account is required to use Affinity. Your account gives access to Affinity along with other Canva products and features. Download: Affinity 3.2.2.4557 | ARM64 | ~600.0 MB (Freeware) Links: Affinity Website | macOS | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Finally we can whole-heartedly recommend the AMD 9070 GRE thanks to this discount by Sayan Sen Earlier this month at Computex 2026 AMD released the Radeon RX 9070 GRE for a global audience. We reviewed the GPU and it scored 8 out of 10 for gaming and 7.5 out of 10 for productivity including things like AI performance. The card launched for $550 which we thought was a bit on the higher side, though currently you are getting the chance to get the Gigabyte Gaming variant of the GPU for just $500 thanks to this discount (purchase link under the specs table down below). As such we can finally whole-heartedly recommend this GPU. The card employs Gigabyte's WINDFORCE cooling system which combines multiple design elements such as alternate-spinning Hawk fans, a vapor chamber, and composite heat pipes to manage heat dissipation. The Server-grade Thermal conductive gel further helps in this department. The inclusion of a semi-passive cooling mode allows the fans to remain inactive under low workloads, which allows for reduced noise operation during lighter usage. There is dual BIOS switch that allows toggling between performance and silent modes. The technical specs of the Gigabyte Gaming RX 9070 GRE OC is given in the table below: Get it at the link below: GIGABYTE Gaming Radeon RX 9070 GRE 12GB GDDR6 GPU (GV-R907GREGAMING OC-12GD): $549.99 + $50 discount with promo code in mail => $499.99 (Sold and Shipped by Newegg US) This Newegg deal is US-specific and not available in other regions unless specified. This is a first-party seller link (at the time of article publishing); ensure that you also purchase from a first-party seller link only. If you don't like it or want to look at more options, check out the previous deals that we have covered, OR you can also visit Amazon US deals page. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an affiliate partner, we earn from qualifying purchases.
    • "to in-game content custom-made for the brands" Which EA will turn around and charge customers extra for in an attempt to double dip.
  • 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
      512
    2. 2
      +Edouard
      205
    3. 3
      PsYcHoKiLLa
      136
    4. 4
      ATLien_0
      89
    5. 5
      Steven P.
      85
  • Tell a friend

    Love Neowin? Tell a friend!