我无法让 xampp 或远程服务器使用我的 php 邮件功能发送电子邮件


I can't get xampp or a remote server to send an email with my php mail function

我已经在我的计算机上为学校项目安装了 xampp,我还可以访问学校的 apache 服务器,在那里我可以上传我的文件并运行它们。

<?php
$headers.= 'MIME-Version: 1.0' . "'r'n";
$headers.= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$rating=$_POST['Rating'];
$subject= "review from website";
$name=$_POST['lname'].", ".$_POST['name'];
$from = $_POST['email'];
$to ="bricebathel@hotmail.com; bbathel@pembaserv.com;".$from.";";
$messageTo="BBComputers";
$headers = "From:" . $from;
$message = htmlspecialchars($_POST['comment']);
$about = $_POST['product'];
$date=date("j-n-y 'a''t g:ia'n");
mail($to,$subject,$message,$headers);
echo "<p id='contactUsData'>Message Sent to: ".$messageTo."<br>Date: ".$date."<br>                       From: ".$name."<br> About: ".$about."<br> Rating: ".$rating."<br> Message:".$message."<//p>";

$file_message="From: ".$name."'nEmail: ".$from."'nAbout: ".$subject."'nRating:   ".$rating."'nMessage: ".$message;
$file= fopen("data/feedback.txt","a")
    or die("Error: Could not open the log file.");
fwrite($file,"'n----------------------------'n")
    or die("Error: Could not open the log file.");
fwrite($file,"Received: ".$date."'n")
    or die("Error: Could not open the log file.");
fwrite($file,$file_message)
    or die("Error: Could not open the log file.");
?>

我无法让它从 xampp 或 apache 服务器发送邮件

您需要一个 smtp 服务器来发送电子邮件。您可以设置一个 sendgrid 帐户,然后使用 sendgrid 类发送电子邮件。API 文档非常好。

http://sendgrid.com/docs/

其他供应商也可用,他们通常每天免费为您提供大约 200 封电子邮件。如果这是一个学校项目,那么你可以逃脱这个配额。

如果您需要发送更多内容,则可能需要考虑设置smpt服务器。或者付钱。

如果您还没有用于发送邮件的 smtp 服务器,则必须设置 smtp 服务器。然后你需要编辑php配置文件以指向该服务器