我是 PHP 新手,并以在线脚本为例。 我已经设置了 Xampp,并且 php 已安装并正常工作。 我尝试使用 hMailServer 设置本地邮件服务器,但是我不完全确定设置是否正确。 不管怎样,这是 PHP 代码:
<?php
$subject="";
$detail="";
$customer_mail="";
$name="";
// Contact subject
$subject ="$subject";
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";
// Enter your email address
$to ='<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5c6d0d4db9bd8ccd0c7c68c87f5d2d8d4dcd99bd6dad8" rel="noreferrer noopener nofollow">[email protected]</a>';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
以及对应的HTML代码:
<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Contact Form </strong></td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="test.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Detail</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
当我提交表单时,出现错误警告:mail() [function.mail]: SMTP 服务器响应:530 需要 SMTP 身份验证。 有什么想法可能是错的吗? 谢谢
最佳答案
来自hMailServer论坛:http://www.hmailserver.com/forum/viewtopic.php?f=6&t=22039
在 IP 范围上。转到我的计算机 IP 范围并取消勾选本地到外部和/或外部到外部的身份验证。
关于php - 如何修复 C : mail() [function. 中的警告 : SMTP server response: 530 SMTP authentication is required. mail] :\xampp\htdocs\. 。第 22 行错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11394099/