douyonglang4845 2013-02-22 05:01
浏览 39
已采纳

如果没有PHP Mailer

I am trying to send a different email to users after the confirmation of registration. One will be for admin users and the other text will be for basic users. I wrote and if else statement based on queried data but its sending both emails to both types of users. Any idea what is wrong?

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, 

".
        "We are a brand new business with big ambitions. Our mission is to help the development of your skills 
".

        "
".
        "Regards,
".
        "Webmaster
".
        $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']."

".
        "Welcome! Your registration  with ".$this->sitename." is completed.
".
        "
".
        "Regards,
".
        "Webmaster
".
        $this->sitename;

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

2条回答 默认 最新

  • douqiandai4327 2013-02-22 05:03
    关注

    In your condtion it should be == rather than =.

    So change

    if($result = 'a')
    

    to

    if($result == 'a')
    

    Note: You are not fetching the record. And It seems that your query must contain a where condition to get business type of user. Not sure though.

    Tip: Why don't you get your common code out of the both condition & just change the mail body content depending on the condition.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器