Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP使用SMTP向不同的收件人发送不同的电子邮件_Php_Email_Smtp - Fatal编程技术网

PHP使用SMTP向不同的收件人发送不同的电子邮件

PHP使用SMTP向不同的收件人发送不同的电子邮件,php,email,smtp,Php,Email,Smtp,我不知道如何在同一个脚本中向recipient1发送包含其信息的电子邮件,然后向recipient2发送包含其信息的电子邮件,向recipient3发送包含其信息的电子邮件,等等 $date=date("Y-m-d"); $time=date("H:i"); $result=mysql_query("select * from reminder where R_Date='$date' && R_Time='$time'"); date_default_timezone_set(

我不知道如何在同一个脚本中向recipient1发送包含其信息的电子邮件,然后向recipient2发送包含其信息的电子邮件,向recipient3发送包含其信息的电子邮件,等等

$date=date("Y-m-d");
$time=date("H:i");
$result=mysql_query("select * from reminder where R_Date='$date' && R_Time='$time'");
date_default_timezone_set( "Asia/Kuala_Lumpur");
$receiver=array();
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'example@gmail.com';                 // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to

while($row=mysql_fetch_assoc($result)){
if($row){
    $mail->From = 'from@example.com';
    $mail->FromName = 'CIMB Clicks';
    $mail->addAddress($row['R_Email'], $row['R_ID']);     // Add a recipient
    $mail->addAddress($row['R_Email']);               // Name is optional
    $mail->WordWrap = 1000;                                 // Set word wrap to 50 characters
    $mail->isHTML(true);                                  // Set email format to HTML
    $body="Greetings from Clicks!<br><br>".

        $row['R_Title'].".<br>".
        "This is My Reminder from Clicks regarding ".$row['R_Title'].".<br><br>".

        "Thank you & have a good day ahead!<br><br>


    $mail->Subject = 'My Reminder from Clicks';
    $mail->Body    = $body;
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

}
}

假设您有一个电子邮件地址数组,则可以进行foreach循环。但是你的问题没有那么详细

$recipients = array('peter@anymail.com', 'paul@anymail.com', 'mary@anymail.com');
$content = 'same content';
$subject = 'same subject';

foreach($recipients as $address) {
    mail($address, $subject, $content, 'FROM: me@anymail.com');
}

你能再详细说明一下吗?几乎不可能猜出你的问题到底是什么。你有一些例子吗?电子邮件如何查找不同的收件人?你能发布一些处理电子邮件发送的代码吗?问题是$row['R_Title'],在我发送给收件人后,它的内容保持不变。我想从数据库中获取不同的内容。是所有电子邮件的文本中都有$row['R_Title'],还是它们都有与数据库中的某个R_Title值相同的文本?所有电子邮件都有$row['R_Title']。在试图从数据库中追加数据的位置周围放置echo()?没有。其实我的问题是关于内容。我无法将确切的内容发送给收件人。
$recipients = array('peter@anymail.com', 'paul@anymail.com', 'mary@anymail.com');
$content = 'same content';
$subject = 'same subject';

foreach($recipients as $address) {
    mail($address, $subject, $content, 'FROM: me@anymail.com');
}