Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.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 如何为我的网站的多个用户发送一封邮件?_Php_Mysql - Fatal编程技术网

Php 如何为我的网站的多个用户发送一封邮件?

Php 如何为我的网站的多个用户发送一封邮件?,php,mysql,Php,Mysql,结果中显示的错误为 Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\elvisstore\sendemail.php on

结果中显示的错误为

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\elvisstore\sendemail.php on line 17
sendmail.php文件如下所示:

<?php
$from = 'something@gmail.com';
$subject =$_POST['subject'];
$text =$_POST['elvismail'];
$dbc= mysqli_connect( 'localhost' , 'smile' ,'password','elvis_store') 
or die('error in connecting to database');

$query = "SELECT * FROM email_list";
$result = mysqli_query($dbc,$query) or die('error in querying data');
//$row = mysqli_fetch_array($result);
while($row=mysqli_fetch_array($result))
{
   $first_name = $row['first_name'];     
   $last_name = $row['last_name']; 
   $msg = "Dear $first_name $last_name, \n  $text" ;
   $to =$row['email']; 
   mail($to, $subject, $msg, 'FROM:' . $from);
   echo "Email sent to $to <br>";
}
  mysqli_close($dbc);
?>

sendmail.html文件

<form method="post" action="sendemail.php"> 

    <label for="subject">Subject of email:</label><br /> 
        <input type="text" id="subject" name="subject" size="60" /><br />     
        <label for="elvismail">Body of email:</label><br />     
        <textarea id="elvismail" name="elvismail" rows="8" cols="60"></textarea><br />     
        <input type="submit" name="submit" value="Submit" />   
    </form> 
</body> 


电子邮件主题:

电子邮件正文:


我认为此错误是由于我正在使用localhost作为我的服务器。请告诉我发生了什么事?

您的localhost上是否安装了任何邮件服务器,或者您正在尝试通过某些外部邮件服务器发送邮件

您需要将这段代码添加到php页面的顶部:

ini_set('SMTP','myserver');
ini_set('smtp_port',25);

将“myserver”替换为要使用的SMTP服务器的ip地址,并为给定服务器使用正确的端口。

请参阅另一篇文章,这将为您提供答案。我用Wamp软件包在离线模式下完成所有这些工作。根据您的说法,我必须粘贴这些代码并用localhost替换myserver,但不知道端口号。端口号取决于您的SMTP服务器。如果你想在本地运行,我建议你使用