0

在确认注册后,我正在尝试向用户发送不同的电子邮件。一个用于管理员用户,另一个文本用于基本用户。我根据查询的数据编写了 if else 语句,但它向这两种类型的用户发送了两封电子邮件。知道有什么问题吗?

function SendBusWelcomeEmail(&$user_rec)
    {
 $result = mysql_query("SELECT business FROM users")
               or die(mysql_error());


if($result='a') {
        $mailer = new PHPMailer();

        $mailer->CharSet = 'utf-8';

        $mailer->AddAddress($user_rec['email'],$user_rec['name']);

        $mailer->Subject = "Welcome to ".$this->sitename;

        $mailer->From = $this->GetFromAddress();        

        $mailer->Body ="Thank You ".$user_rec['name']." for joining xxx, \r\n\r\n".
        "We are a brand new business with big ambitions. Our mission is to help the development of your skills \r\n".

        "\r\n".
        "Regards,\r\n".
        "Webmaster\r\n".
        $this->sitename;
}
        if(!$mailer->Send())
        {
            $this->HandleError("Failed sending user welcome email.");
            return false;
        }
        else{
        $mailer = new PHPMailer();

        $mailer->CharSet = 'utf-8';

        $mailer->AddAddress($user_rec['email'],$user_rec['name']);

        $mailer->Subject = "Welcome to ".$this->sitename;

        $mailer->From = $this->GetFromAddress();        

        $mailer->Body ="Hello ".$user_rec['name']."\r\n\r\n".
        "Welcome! Your registration  with ".$this->sitename." is completed.\r\n".
        "\r\n".
        "Regards,\r\n".
        "Webmaster\r\n".
        $this->sitename;

        if(!$mailer->Send())
        {
            $this->HandleError("Failed sending user welcome email.");
            return false;
        }
}
    }
4

2 回答 2

4

在您的条件下,它应该是==而不是=.

所以改变

if($result = 'a')

if($result == 'a')

注意:您没有获取记录。而且您的查询似乎必须包含获取业务类型用户的 where 条件。不过不确定。

提示:为什么不从这两个条件中获取通用代码,只需根据条件更改邮件正文内容。

于 2013-02-22T05:03:08.043 回答
2

在这条线之后

$result = mysql_query("SELECT business FROM users") or die(mysql_error());

用于获取结果。

$result = mysql_fetch_array($result);
于 2013-02-22T05:05:54.343 回答