gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 23:16:48 26 4
gpt4 key购买 nike

结果显示错误为

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>

我认为这个错误是由于我使用本地主机作为我的服务器造成的。请告诉我发生了什么事?

最佳答案

您的本地主机上是否安装了任何邮件服务器,或者您是否尝试通过某些外部邮件服务器发送邮件?

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

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

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

关于php - 如何为我网站的多个用户发送一封邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27720395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com