Swiftmailer와 함께 이메일을 보내십시오
-
08-07-2019 - |
문제
현재 사용 중입니다 스위프트 메일러 여러 사용자에게 이메일을 보내려면 (최대 50 명). 제대로 설정하고 제대로 작동했지만 MySQL 데이터베이스에서 수신자를 끌어 당기고 반복하여 보내는 방법을 잘 모르겠습니다.
내가 현재 가지고있는 것은 다음과 같습니다.
<?php
require_once 'swift/lib/swift_required.php';
$mailer = Swift_Mailer::newInstance(
Swift_SmtpTransport::newInstance('smtp.connection.com', 25)
->setUsername('myUserName')
->setPassword('myPassword')
);
$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(9));
$message = Swift_Message::newInstance()
->setSubject('Let\'s get together today.')
->setFrom(array('myfrom@domain.com' => 'From Me'))
->setTo(array('tom_jones@domain.com' => 'Tom Jones', 'jsmith@domain.com' => 'Jane Smith', 'j_doe@domain.com' => 'John Doe', 'bill_watson@domain.com' => 'Bill Watson',))
->setBody('Here is the message itself')
->addPart('<b>Test message being sent!!</b>', 'text/html')
;
$numSent = $mailer->batchSend($message, $failures);
printf("Sent %d messages\n", $numSent);
위에서 볼 수 있듯이 Setto에서 데이터베이스의 사용자와 반복하고 싶습니다. 같은 것 :
SELECT first, last, email FROM users WHERE is_active=1
그만큼 선적 서류 비치 상태 :
Note: Multiple calls to setTo() will not add new recipients – each call overrides the previous calls. If you want to iteratively add recipients, use the addTo() method.
하지만 확실하지 않습니다. 1: 이 스크립트에서 내 DateBase에서 선택하는 방법 : 2: 제 경우에는 addto () 메소드를 사용해야하는 경우. 이것을 제대로 설정하는 방법에 대한 제안이 있습니까?
감사!
해결책
나는 당신의 질문을 제대로 얻었는지 확신하지 못하지만 여기에 그것을하는 방법이 있습니다.
<?php
$message = Swift_Message::newInstance()
->setSubject('Let\'s get together today.')
->setFrom(array('myfrom@domain.com' => 'From Me'))
->setBody('Here is the message itself')
->addPart('<b>Test message being sent!!</b>', 'text/html')
;
$data = mysql_query('SELECT first, last, email FROM users WHERE is_active=1') or die(mysql_error());
while($row = mysql_fetch_assoc($data))
{
$message->addTo($row['email'], $row['first'] . ' ' . $row['last']);
}
$message->batchSend();
?>
나는 그것이 당신이 원했던 것이기를 바랍니다.
제휴하지 않습니다 StackOverflow