简体   繁体   English

PHP通过SQL将电子邮件发送到多个地址

[英]PHP Send email to multiple address from SQL

I'm trying to send emails to multiple address pulled from SQL. 我正在尝试将电子邮件发送到从SQL提取的多个地址。 I came up with following script but no luck. 我想出了以下脚本,但没有运气。 I know that using mail() or sendmail is not best choice, if anybody can point out where I went wrong or have a better solution using phpmailer that would be brilliant. 我知道使用mail()sendmail并不是最好的选择,如果有人可以指出我出了错的地方,或者使用phpmailer有更好的解决方案,那将是很棒的选择。

PS: I do not want to use SMTP as we are using an address that we will not be monitoring. PS:我不想使用SMTP,因为我们正在使用的地址将不受监视。 The Do-NOT-REPLY one, actually we don't have email service at all. 不要回答,实际上我们根本没有电子邮件服务。 But server does support mail/sendmail/phpmailer, all tested. 但是服务器确实支持mail / sendmail / phpmailer,所有都经过测试。

<HTML> 
   <TITLE>Email Notification</TITLE> 
<?php

include "subscribe/mySQL.class.php"; //Connect to SQL 

if ($subject) { 
    $mailaddress = "DO-NOT-REPLY@domain.my";
    $query = "select email from subscribe"; 
    $res = mysql_query($query); 
    $row = mysql_fetch_array($res); 

    while ($row) { 

        mail($row['email'],$subject,$text."n ","From:".$mailaddress); 
        $row = mysql_fetch_array($res);

    } 

    echo "<script type='text/javascript'>"; 
    echo "parent.location.href='welcome.php'"; 
    echo "</script>";} 
?> 
<BODY> 
<P ALIGN=CENTER><FONT FACE="Arial" SIZE="7" COLOR="#FF0000">Send Notifications<BR><BR></FONT> 
<P ALIGN=LEFT><FORM NAME="email" ACTION="test.php" METHOD="POST"> 
<FONT FACE="Arial" SIZE="6" COLOR="#0000FF">Subject:<INPUT TYPE=TEXT NAME="subject" SIZE="50" MAXLENGTH="18" value=<?php echo $subject ?>><BR><BR> 
Content: <TEXTAREA NAME="text" COLS="90" ROWS="3" value="<?php echo $text?>"> </TEXTAREA><BR><BR> 
</FONT> 
<INPUT TYPE=SUBMIT VALUE=Send Email></FORM> 
</BODY> 
</HTML>

You see nothing because you don't print anything to help you see that the email was sent. 您什么也看不到,因为您没有打印任何内容来帮助您查看电子邮件已发送。

Try using: mysql_fetch_assoc() instead of mysql_fetch_array() and see how it works for you. 尝试使用: mysql_fetch_assoc()而不是mysql_fetch_array(),看看它如何为您工作。

//Sorry, but I am a fan of mysql_fetch_assoc 
//$row = mysql_fetch_array($res); 

while ($row = mysql_fetch_assoc($res)) { //Here is my main change

    if (mail($row['email'],$subject,$text."n ","From:".$mailaddress)) {
       echo '<hr>Message sent to: '.$row['email'].'<br>'; //Just to see that it was sent.
    }

    //$row = mysql_fetch_array($res); //Since I put this in the while test

} 

The mail() function returns a boolean value, so test that value and print something so that you can know if the mails was succesfully sent. mail()函数返回一个布尔值,因此测试该值并打印一些内容,以便您可以知道是否成功发送了邮件。

Let me know if this is not problem, that way I can either delete this answer or edit it accordingly. 如果这不是问题,请告诉我,这样我可以删除此答案或进行相应的编辑。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Z2FEC392304A5C23AC13ZZDA22847F9B7 从 MySQL 将 email 发送到所有 email 地址 - Send email to all email address from MySQL using PHP php电子邮件未从指定的发件人:地址发送 - php email doesn't send from specified From: address php 将在 mail() 函数中从哪个电子邮件地址发送 - From which email address will php send in mail() function 如何通过php mailer发送电子邮件到从数据库获取的地址 - How to send email to address fetched from database via php mailer 使用PHP将电子邮件从APP Engine应用程序发送到Gmail地址 - Send Email to a Gmail address from an APP Engine Application using PHP 如何使用 php 发送 email,其中收件人地址从 mySQL 中选择? - How to send a email with php where the recipient address is selected from mySQL? 将电子邮件发送到从PHP数据库中检索到的多个电子邮件地址 - Send an email to multiple email addresses retrieved from the database in PHP 电子邮件从自己的电子邮件地址发送 - Email gets send from own email address 如果发件人地址来自雅虎电子邮件地址,则我的php()邮件脚本不会发送电子邮件 - My php() mail script wont send emails if the from address is from a yahoo email address 我正在尝试使用PHP从FORM发送电子邮件,但是我收到的详细信息没有发件人电子邮件地址 - I am trying to send email from a FORM using PHP, but i receive the details without the From email Address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM