how to pass variable to Swift_Address?

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
ashleyK
Forum Newbie
Posts: 11
Joined: Tue Mar 18, 2008 8:10 am

how to pass variable to Swift_Address?

Post 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";
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: how to pass variable to Swift_Address?

Post 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);
ashleyK
Forum Newbie
Posts: 11
Joined: Tue Mar 18, 2008 8:10 am

Re: how to pass variable to Swift_Address?

Post by ashleyK »

Smashing - thanks!!
Post Reply