2

私は問題があります。送信ボタンをクリックするとzxc@hotmail.com、メッセージが届きます。

それを変更する方法は?GmailSMTP送信を使用しています。

データベースには2つのレコードがあります。

これが私のコードです:

include "phpmailer/class.phpmailer.php";
$host = "localhost";
$user = "root";
$pass = "root";
$db = "mailTest";

mysql_connect($host, $user, $pass);
mysql_select_db($db);

$query = "SELECT email FROM list";

$recordset = mysql_query($query);
$row_recordset = mysql_fetch_assoc($recordset);
$tota_row_recordset = mysql_num_rows($recordset);
$msg = strip_tags($_POST['msg']);
$mail= new PHPMailer(); //建立新物件 
while($row = mysql_fetch_array($recordset))
{
    $to = $row['email'];
    $mail->AddAddress($to, "Test Message"); 
}      
$mail->IsSMTP();    
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";     
$mail->Port = 465;      
$mail->CharSet = "big5";
$mail->Subject = "Test Message";     
$mail->Username = "xxxxxx";    
$mail->Password = "xxxxxx";   
$mail->Body = "$msg";
$mail->IsHTML(true);           
if(!$mail->Send()) {      
echo "Mailer Error: " . $mail->ErrorInfo;       
} else {      
header('Location: index.php');
}
4

3 に答える 3

4

このループでは、反復ごとに受信者を上書きするため、最後の1つだけが電子メールの受信に留まります。

while($row = mysql_fetch_array($recordset))
{
    $to = $row['email'];
}
$mail = new PHPMailer(); 

コードを次のように変更します

$mail = new PHPMailer(); // create object FIRST
while($row = mysql_fetch_array($recordset))
{
    $to = $row['email'];
    $mail->AddAddress($to, "Test Message"); // add each DB entry to list of recipients
}
于 2012-05-11T18:04:11.957 に答える
3

以下でこれを試してください:

while($row = mysql_fetch_array($recordset))
{
    $to = $row['email'];
    $mail= new PHPMailer();
    $mail->IsSMTP();

    $mail->SMTPAuth = true;

    $mail->SMTPSecure = "ssl";

    $mail->Host = "smtp.gmail.com";

    $mail->Port = 465;

    $mail->CharSet = "big5";

    $mail->Subject = "Test Message";

    $mail->Username = "xxxxxx";

    $mail->Password = "xxxxxx";

    $mail->Body = "$msg";

    $mail->IsHTML(true);

    $mail->AddAddress($to, "Test Message");

    if(!$mail->Send()) {

    echo "Mailer Error: " . $mail->ErrorInfo;
    }
}    
于 2012-05-11T18:03:17.810 に答える
0
if(isset($_POST['sbmit']))
{
    for($i=0;$i<count($_POST['email_address']);$i++)
    {

          $to = $_POST['email_address'][$i];
          echo $to."<br />";
          $subject = 'Thank you for Subscribing';
          $message = $_POST['news'];
          $headers = 'From: dhakalneil@gmail.com' . "\r\n" .
          'Reply-To: xyz@hotmail.com' . "\r\n" .
          'X-Mailer: PHP/' . phpversion();


         echo $_POST['email_address'][$i]."<br />";
         ini_set("SMTP","smtp.ntc.net.np" );
         ini_set('sendmail_from', 'dhakalneil@gmail.com');
         if( mail($to,$subject,$message,$headers))
         {
                echo "Mail has been sent to admin<br />";
         }
         else
         {
                echo "Mail could not been sent";
         } 

    }
}


?>
于 2013-04-11T06:21:35.460 に答える