• 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.