结果中显示的错误是
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);
?>
sendemail.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作为我的服务器。请告诉我发生了什么事?
答案 0 :(得分:0)
您的本地主机上是否安装了任何邮件服务器,或者您是否尝试通过某些外部邮件服务器发送?
您需要将这段代码添加到php页面的顶部:
ini_set('SMTP','myserver');
ini_set('smtp_port',25);
替换“myserver”的地方使用您要使用的SMTP服务器的IP地址,以及使用给定服务器的正确端口。