내 워드 프레스 사이트 데이터베이스에서 사용자 이메일 주소를 가져 오는 PHP 스크립트가 있습니다. 다음과 같이 PHP 스크립트
$sql = "SELECT user_email FROM wp_users";
$addr = mysqli_query($conn,$sql);
while ($row = mysqli_fetch_assoc($addr)){
printf ("%s\n", $row["user_email"]);
}
출력은 다음과 같습니다.
내 파이썬 코드에서 나는 urllib2
PHP를 읽는 데 사용 하고 파이썬 스 니펫은 다음과 같습니다.
response = urllib2.urlopen('http://192.168.0.168/useremail.php')
status = response.read()
fromaddr = "[email protected]"
toaddr = status
server.sendmail(fromaddr, toaddr)
이 경우 이메일은 PHP 스크립트에서 검색된 여러 이메일 주소가 있음에도 불구하고 항상 첫 번째 이메일 주소로만 전송됩니다. 이 문제를 해결하도록 도와주세요. 제가 프로그래밍 초보자라고 말해서 죄송합니다.
sendmail()
메일 주소 목록이 필요합니다. 따라서 urllib2의 응답으로 해당 목록을 작성해야합니다.
splitlines()
문자열의 행 목록을 반환하는 데 사용 합니다.
즉 :
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
# ['[email protected]', '[email protected]', '[email protected]', '[email protected]']
# then send the mails
fromaddr = "[email protected]"
server.sendmail(fromaddr, mail_list)
도움이 되었기를 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다