Hey all, not sure what im doing wrong here…
I integrated Swiftmail into my app, so I made a very small wrapper so I could call it without having to construct it in my controllers.
Here are some snippets:
class Email
{
private $_mail;
private $_transport;
public function __construct()
{
$this->_transport = \\Swift_SmtpTransport::newInstance(SMTP_HOST, SMTP_PORT, SMTP_SSL)
->setUsername(SMTP_USER)
->setPassword(SMTP_PASS);
$this->_mail = \\Swift_Message::newInstance();
}
public function send($subject, &$from, &$to, $body, $part = null, $type = 'text/html', $attachment = null)
{
// Check to see if we get our array,
// which we do and get the correct output as expected:
// array(1) { ["myemail@gmail.com"]=> string(12) "My Name" }
var_dump($to);
// Give the message a subject
$this->_mail->setSubject($subject)
// Set the From address with an associative array
->setFrom($from)
// Set the To addresses with an associative array
->setTo($to)
// Give it a body
->setBody($body);
//------ and the rest
So, setFrom() and setTo() expect an array, from their documentation:
->setFrom(array('john@doe.com' => 'John Doe'))
->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
Im passing the array like so:
//From within my controller class im calling send() like:
// Note _mail is NOT the same _mail property in Email()
$to = array('myemail@gmail.com' => 'My Name');
$from = array('myemail@gmail.com' => 'My Name');
$this->_mail->send('This is the subject', $from, $to, 'this is my email body');
However, I get an error, which shows this:
[COLOR=#333333][FONT=Open Sans]Email->send(‘This is the sub…’, Array, Array, 'this is my emai… in
It’s only seeing Array, Array for the To and From…
What am I doing wrong?![/FONT][/COLOR]