doushi8187 2016-11-12 05:51
浏览 57
已采纳

too long

I have a php script to fetch user email address from my wordpress site database. The php script as follow

$sql = "SELECT user_email FROM wp_users";
$addr = mysqli_query($conn,$sql);

while ($row = mysqli_fetch_assoc($addr)){
        printf ("%s
", $row["user_email"]);
}

The output will look like this

abcd@gmail.com

ggyy@gmail.com

In my python code i use urllib2 to read the php and the python snippet look like this

response = urllib2.urlopen('http://192.168.0.168/useremail.php')
status = response.read()

fromaddr = "testing123@gmail.com"
toaddr = status
server.sendmail(fromaddr, toaddr)

In this case, the email always sent to the first email address only despite there are several email address retrieve from the php script. Please help me to solve this problem. Sorry to say that I am a beginner in programming.

  • 写回答

1条回答 默认 最新

  • douhezhan5348 2016-11-12 07:07
    关注

    sendmail() needs a list of mail addresses. So, you'll need to build that list with the response of urllib2.

    Use splitlines() to return a list of the lines in the string.

    i.e. :

    import urllib2
    
    response = urllib2.urlopen('http://192.168.0.168/useremail.php')
    status = response.read()
    
    mail_list = status.splitlines() # split the response in a list 
    
    print mail_list
    # ['john@doe.tld', 'smyth@noon.tld', 'arthur@excalibur.tld', 'george@dada.tld']
    
    # then send the mails    
    fromaddr = "testing123@gmail.com"
    server.sendmail(fromaddr, mail_list)
    

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测