2

我是 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 ='sean.myers92@gmail.com';
$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>&nbsp;</td>
<td>&nbsp;</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 server response: 530 SMTP authentication is required。有什么想法可能是错的吗?谢谢

4

5 回答 5

5

来自 hMailServer 的论坛:http ://www.hmailserver.com/forum/viewtopic.php?f=6&t=22039

在 IP 范围内。转到我的计算机 IP 范围并取消勾选本地到外部和/或外部到外部的身份验证。

于 2012-11-22T19:55:17.227 回答
0

它的 php 未配置您可以更新以指向 php.ini 中的有效 smtp 服务器查找[mail function]这仅适用于 Windows 您可能希望在本地设置邮件服务器,因为不支持密码或使用 http:// sourceforge.net/projects/phpmailer支持登录

于 2012-07-09T11:39:29.290 回答
0

从此链接http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list下载最新的 phpmailer并阅读其 gmail 教程。对我来说,它也适用于本地系统:) + 这是非常简单的教程。

于 2012-07-09T11:42:32.007 回答
0

Xampp 没有内置邮件服务器。您需要设置一个。

PHP 的邮件问题,无法发送

使用 XAMPP 发送邮件时出错

另一种方法是使用另一个 stmp 服务器(即 googlemail)和一个邮件库,如 PEAR:Mail 或 swiftmailer 来建立一个 imap/smtp 连接和登录凭据

于 2012-07-09T11:26:08.333 回答
-2

/** * 返回错误字符串,如果成功则返回 null */


function authSendEmail($sendto, $replyto, $subject, $message, $namefrom=""){
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * /
$smtpServer = "mail.server.com";
$端口=“25”;
$timeout = "5";
$username = "test@server.com";
$密码=“测试”;
$newLine = "\r\n";
/
* * * 配置结束 * * * * */

  /*
  2ХХ — команда успешно выполнена
  3XX — ожидаются дополнительные данные от клиента
  4ХХ — временная ошибка, клиент должен произвести следующую попытку через некоторое время
  5ХХ — неустранимая ошибка
  */


  //0    //Connect to the host on the specified port
      $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
      $smtpResponse = fgets($smtpConnect, 1024);
      if(empty($smtpConnect) || $smtpResponse{0} !='2' )
      {
        return  "Failed to connect: $smtpResponse";
      }


  //1    //hello server
      fputs($smtpConnect,"EHLO servername" . $newLine);
      $smtpResponse = fgets  ($smtpConnect);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";

      $smtpResponse = fgets  ($smtpConnect);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";

      $smtpResponse = fgets  ($smtpConnect);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";
      $smtpResponse = fgets  ($smtpConnect);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";
      $smtpResponse = fgets  ($smtpConnect);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";
      $smtpResponse = fgets  ($smtpConnect);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";

  //2    //Request Auth Login
      fputs($smtpConnect,"AUTH LOGIN" . $newLine);
      $smtpResponse = fgets($smtpConnect, 1024);
      if($smtpResponse{0} !='3' )
        return "Failed: $smtpResponse";

  //3    //Send username
      fputs($smtpConnect,  base64_encode($username).$newLine);
      $smtpResponse = fgets($smtpConnect, 1024);
      if($smtpResponse{0} !='3' )
        return "Authentification failed: $smtpResponse";

  //4    //Send password
      fputs($smtpConnect,  base64_encode($password).$newLine);
      $smtpResponse = fgets($smtpConnect, 1024);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";


  //6    //Email From
      fputs($smtpConnect, "MAIL FROM: ".$username . $newLine);
      $smtpResponse = fgets($smtpConnect, 1024);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";

  //7    //Email To
      fputs($smtpConnect, "RCPT TO: ".$sendto . $newLine);
      $smtpResponse = fgets($smtpConnect, 1024);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";

  //8    //The Email
      fputs($smtpConnect, "DATA" . $newLine);
      $smtpResponse = fgets($smtpConnect, 1024);
      if($smtpResponse{0} !='3' )
        return "Failed: $smtpResponse";

  //9 //Construct Headers
      $headers = "MIME-Version: 1.0" . $newLine;
      $headers .= "Content-type: text/html; charset=windows-1251" . $newLine;
      $headers .= "To: Администратор <$sendto>" . $newLine;
      $headers .= "From: $namefrom <$username>" . $newLine;
      $headers .= "Reply-To: $namefrom <$replyto>" . $newLine;
      $headers .= "X-Mailer: ".phpversion(). $newLine;

      fputs($smtpConnect, "Subject: $subject\n$headers\n\n$message\n.\n" );
      $smtpResponse = fgets($smtpConnect, 515);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";


  //10    // Say Bye to SMTP
      fputs($smtpConnect,"QUIT" . $newLine);
      $smtpResponse = fgets($smtpConnect, 1024);
      if($smtpResponse{0} !='2' )
        return "Failed: $smtpResponse";

      return false;
}

?>
于 2012-07-09T11:54:38.067 回答