Mail PEAR包不发送电子邮件

时间:2014-07-22 14:36:51

标签: php mysql email smtp

我有一个脚本设置,应该根据查询发送电子邮件。代码是这样的:

$firemail = mysql_query("SELECT `email` from `users` WHERE `reference` = ''$customer' ");
$to      = $firemail;

忽略这不是PDO这一事实我然后将$ firemail传递给smtp,如下所示:

$headers = array (
    'From' => $from,
    'To' => $firemail,
    'Subject' => $subject,
    'Reply-To' => 'test@test.com',
    'MIME-Version' => "1.0",
    'Content-type' => "text/html; charset=iso-8859-1\r\n\r\n");
    $smtp = Mail::factory('smtp', array(
        'host' => 'smtp.myservice.com',
        'port' => '123',
        'auth' => true,
        'username' => 'user@test.com',
        'password' => 'supersecretpassword'
    ));

我已经测试过SMTP工作,当我手动输入收件人时,它会按设计发送电子邮件。 $ firemail包含的查询是有效的,并返回预期的结果。我已经回显了$ customer var,这会返回预期的结果。

因此假设我的所有代码都是有效的并且应该按原样运行。为什么我没有收到电子邮件?

谢谢!

1 个答案:

答案 0 :(得分:1)

这是返回一个mysql对象而不是结果:

$firemail = mysql_query("SELECT `email` from `users` WHERE `reference` = ''$customer' ");
$to = $firemail;

应该是:

$result = mysql_query("SELECT `email` from `users` WHERE `reference` = ''$customer'");

while ($fila = mysql_fetch_assoc($result)) {
  $firemail[] = $fila['email']
}