Page 1 of 1

how to pass variable to Swift_Address?

Posted: Tue Mar 18, 2008 8:16 am
by ashleyK
It seems like a very basic question so sorry if I have missed something obvious...

I'm trying to send a 'from' name and e-mail in a variable to Swift_Address but it doesn't seem to like it.

this works:

if ($swift->send($message, new Swift_Address($email), new Swift_Address("info@XXX.com", "XXX name"))) echo "Sent";
else echo "Failed";

this doesn't work

$from = '"info@XXX.com", "XXX name"';
if ($swift->send($message, new Swift_Address($email), new Swift_Address($from))) echo "Sent";
else echo "Failed";

Re: how to pass variable to Swift_Address?

Posted: Tue Mar 18, 2008 8:50 am
by Zoxive
That's because Swift Address wants 2 parameters, and you are only giving it one.

Code: Select all

$from = array('email@site.com','name');
new Swift_Address($from[0],$from[1]);
Same as

Code: Select all

$from1 = 'email@site.com';
$from2 = 'name';
new Swift_Address($from1,$from2);

Re: how to pass variable to Swift_Address?

Posted: Tue Mar 18, 2008 8:58 am
by ashleyK
Smashing - thanks!!