用php发送信息

时间:2013-06-05 10:13:00

标签: php mysql email smtp-auth

我有一个简单的密码发送,当他们输入电子邮件时会向他们发送密码,但唯一的问题是我在加载显示的页面时收到错误

  

无法添加收件人:@localhost [SMTP:响应代码无效   从服务器收到(代码:501,响应:< @ localhost>:没有本地   部分)]

我知道这些信息是正确的。这是代码 - (是的,我知道不使用mysqli是不安全的。这是一个快速的事情。)

 <?php
  $username = "sdfsdfsdf";
  $password = "sdfsdfsdf";
  $hostname = "dsfsdfsdf";    
  $dbconn = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
  $emailto  = $_POST['email'];

  $database = mysql_select_db("jjlliinn_test",$dbconn);

  $query  = "SELECT password FROM agentclient WHERE email = '$emailto'";
  $result = mysql_query($query) or die(mysql_error());
  $data = mysql_fetch_assoc($result);



// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // 
 require_once "Mail.php";

 $from = "JLP <no-reply@sdfsdfsdfsdfsdfsdfsdf.net>";
 $to = "$toemail";
 $subject = "Your password";
 $body = "Hi,\n\nYour password is $data.";

 $mailhost = "mail.sdfsdfsdfsdf.net";
 $mailusername = "no-reply@sdfsdfsdfsdf.net";
 $mailpassword = "Uq?sdfsdfsdfsdfsdf-";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $mailhost,
     'auth' => true,
     'username' => $mailusername,
     'password' => $mailpassword));

 $mail = $smtp->send($to, $headers, $body);

 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Password successfully sent!</p>");
  }
    mysql_close($dbconn);  
 ?>

2 个答案:

答案 0 :(得分:0)

您没有在本地主机上配置SMTP服务器,您应该在此处查看:

How to configure WAMP (localhost) to send email using Gmail? http://rajeshstutorials.blogspot.com/2012/04/how-to-set-up-smtp-server-on-localhost.html

应该有帮助。

答案 1 :(得分:0)

由于此错误,您的代码会向localhost发送任何电子邮件:

 $to = "$toemail"; # empty-string assignment! Should be "$emailto"