• 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

    • they should stop making bad games that no one asked for
    • Nice rant! Expletive after expletive after expletive. Poor petal, I've touched a nerve. Would you like a tissue to wipe those tears away. Btw, nice one calling Neowin trash. Why would you stick around when you disrespect this site and the people behind it? Just go away if you feel that way.
    • Internet Download Manager (IDM) 6.43 Build 1 by Razvan Serea Internet Download Manager (IDM) is a tool to increase download speeds by up to 8 times due to its smart dynamic file segmentation technology. Unlike other download managers and accelerators, Internet Download Manager segments downloaded files dynamically during download process, and it reuses available connections without additional connect and login stages to achieve the best possible acceleration performance. Comprehensive error recovery and resume capability will restart broken or interrupted downloads due to lost connections, network problems, computer shutdowns, or unexpected power outages. All popular browsers are supported IDM integrates seamlessly into Google Chrome, FireFox, Microsoft Edge, Opera, Safari, Internet Explorer, Maxthon and all other popular browsers to automatically handle your downloads. You can also drag and drop files, or use Internet Download Manager from command line. The program supports proxy servers, ftp and http protocols, firewalls, redirects, cookies, authorization, MP3 audio and video content processing. IDM includes web site spider and grabber IDM downloads all required files that are specified with filters from web sites, for example all pictures from a web site, or subsets of web sites, or complete web sites for offline browsing. It's possible to schedule multiple grabber projects to run them once at a specified time, stop them at a specified time, or run periodically to synchronize changes. Easy downloading with one click When you click on a download link in a browser, IDM will take over the download and accelerate it. You don't need to do anything special, just browse the Internet as you usually do. IDM will catch your downloads and accelerate them. IDM supports HTTP, FTP, HTTPS and MMS protocols. Changes in Internet Download Manager 6.43 Build 1: Added the ability to download MP4 files from web sites where previously only TS videos were available. IDM displays both TS and MP4 file formats in its video download button. If you only need MP4 files, disable TS in IDM Options -> General tab -> Customize IDM Download panels in browsers -> Edit button. Remove TS extension on "Customize IDM Download panel in browsres" dialog Fixed video downloading problems on several popular web sites Fixed bugs Download: Internet Download Manager 6.43 Build 1 | 11.9 MB (Shareware) Links: Internet Download Manager Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • This is of course "clickbait" WTF? It is literally your example but tech based. A "clickbait" title is a sensationalized headline designed to manipulate readers into clicking a link using things like "fear" rather than delivering objective facts. A "clickbait" headline also usually provides little value compared to the hype generated. How does this headline not qualify? It's a generic often reused headline that is overly sensationalized. Oh no! "millions" can't use this app anymore. It has no basic facts like what f*cking app. You read the article and it's the Samsung VPN which no one cares about and there is a million free VPNs. How are you defending this ######? Headlines like this (and among other things) make me read Neowin much less than I used to in the past. It's trash...
  • Recent Achievements

    • Veteran
      branfont went up a rank
      Veteran
    • Reacting Well
      Almohandis earned a badge
      Reacting Well
    • First Post
      Cosminus earned a badge
      First Post
    • One Year In
      ThatGuyOnline earned a badge
      One Year In
    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      473
    2. 2
      +Edouard
      181
    3. 3
      PsYcHoKiLLa
      122
    4. 4
      Steven P.
      85
    5. 5
      neufuse
      73
  • Tell a friend

    Love Neowin? Tell a friend!