Whats best? setFrom(array($fm_email => $fm_name)) or with ""

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
geddi
Forum Commoner
Posts: 39
Joined: Sun Feb 24, 2008 11:01 am

Whats best? setFrom(array($fm_email => $fm_name)) or with ""

Post by geddi »

Hello,

Chris said that both of these will work:

// set the sender
$message->setFrom(array($fm_email => $fm_name));

OR

// set the sender
$message->setFrom(array("$fm_email" => "$fm_name"));

But does it matter which is used ?

Just want to avoid problems later on :)
geddi
Forum Commoner
Posts: 39
Joined: Sun Feb 24, 2008 11:01 am

Re: Whats best? setFrom(array($fm_email => $fm_name)) or with ""

Post by geddi »

I got this reply from another forum.

Hope it helps someone :)

It won't make a difference in this case, the variables in double quotations will be parsed as PHP.
However, go without them in order to improve performance. Double quoted strings take slightly longer to execute since the interpreter has to determine if the string requires parsing or not.
echoDreamz
Forum Newbie
Posts: 9
Joined: Sat Feb 21, 2009 7:54 am

Re: Whats best? setFrom(array($fm_email => $fm_name)) or with ""

Post by echoDreamz »

Also I heard that you can do "{$variable}" and PHP will automatically parse $variable.

This is just something I have been doing for years etc.
coolfactor
Forum Newbie
Posts: 4
Joined: Thu May 07, 2009 1:20 pm

Re: Whats best? setFrom(array($fm_email => $fm_name)) or with ""

Post by coolfactor »

echoDreamz wrote:Also I heard that you can do "{$variable}" and PHP will automatically parse $variable.

This is just something I have been doing for years etc.
Yes, I use the "{$variable}" format since it makes the string much easier to read.

Example:

Code: Select all

$str = "Your special coupon code is {$coupon_code}. Please enter this when completing your purchase.";
While also being easier to read, using parsed variables is also slightly more efficient than using concatenation.

Code: Select all

$str = 'Your special coupon code is '.$coupon_code.'. Please enter this when completing your purchase.';
Post Reply