php中的mail()不起作用?

时间:2014-03-02 13:20:21

标签: php

CODE:

<h2>Feedback Form</h2>
<?php
ini_set('display_errors',1);
// display form if user has not clicked submit
if (!isset($_POST["submit"]))
  {
  ?>
  <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
  From: <input type="text" name="from"><br>
  Subject: <input type="text" name="subject"><br>
  Message: <textarea rows="10" cols="40" name="message"></textarea><br>
  <input type="submit" name="submit" value="Submit Feedback">
  </form>
  <?php 
  }
else
  // the user has submitted the form
  {
  // Check if the "from" input field is filled out
  if (isset($_POST["from"]))
    {
    $from = $_POST["from"]; // sender
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    // message lines should not exceed 70 characters (PHP rule), so wrap it
    $message = wordwrap($message, 70);
    // send mail
    mail("samy_zaki@ymail.com",$subject,$message,"From: $from\n");
    echo "Thank you for sending us feedback";
    }
  }
?>

错误: 警告:mail():SMTP服务器响应:550-5.1.1您尝试访问的电子邮件帐户不存在。请在第30行的C:\ Program Files \ EasyPHP-12.0 \ www \ contact us.php中试用 感谢您向我们发送反馈

1 个答案:

答案 0 :(得分:0)

使用php.ini

  • 打开php.ini

  • SMTP中搜索php.ini。通常,您会找到SMTP=localhost。将localhost更改为ISP的smtp服务器名称。并设置25的端口。

    SMTP = aspmx.l.google.com # your smtp server address
    smtp_port = 25
    
  • 重启Apache服务器

  • 现在尝试使用mail()功能

  • 发送邮件

使用ini_set:

<?php
ini_set('SMTP',"aspmx.l.google.com"); // your smtp server address
ini_set('smtp_port',25);
?>

来源:Sending email with PHP