How to fix Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\xampp\htdocs\.. on line 22 ERROR

泄露秘密 提交于 2019-12-23 22:16:07

问题


I'm new to PHP and have taken a script as an example online. I have setup Xampp and the php is installed and working. I've attempted to setup a local mailserver with hMailServer, however I'm not entirely sure if that's setup correctly. Anyhow, here's the PHP code:

<?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";
}
?>

And the corresponding HTML code:

<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>

When I submit the form I get the error Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. Any ideas what could be wrong? Thanks


回答1:


From the forums of hMailServer: http://www.hmailserver.com/forum/viewtopic.php?f=6&t=22039

On the IP ranges. goto the my computer ip range and untick authentication for local to external and/or external to external.




回答2:


Xampp has no Mail server build in. You'll need to set one up.

Mail issues with PHP, Unable to send

Error on sending mail with XAMPP

alternative use another stmp server (ie googlemail) and a mail library such as PEAR:Mail or swiftmailer to establish a imap/smtp connection with login credentials




回答3:


its php that's not configured you can update to point to a valid smtp server in the php.ini look up [mail function] this is for windows only you may want to set up mail server locally as does not support passwords or use phpmailer available from http://sourceforge.net/projects/phpmailer which does support logins




回答4:


Download the latest phpmailer from this link http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list and read its gmail tutorial. for me it works from local system too :) + it's very simple tutorial.




回答5:


/** * return error string or null if success */


function authSendEmail($sendto, $replyto, $subject, $message, $namefrom=""){
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * /
$smtpServer = "mail.server.com";
$port = "25";
$timeout = "5";
$username = "test@server.com";
$password = "test";
$newLine = "\r\n";
/
* * * CONFIGURATION END * * * * */

  /*
  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;
}

?>


来源:https://stackoverflow.com/questions/11394099/how-to-fix-warning-mail-function-mail-smtp-server-response-530-smtp-authe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!