dqvzfp6468 2016-06-27 10:29
浏览 20

mail()在php中不起作用[重复]

This question already has an answer here:

I am using mail() function to sent mails when an event happening. But it is not working as I expected. I tried to get the return of the function also. Some one please suggst what may be the issue.

        $msg = "Your password has been changed.is'".$data['password']."'";
        $to = $data['email'];
        $subject = "password changed";
        $headers = 'MIME-Version: 1.0' . "
";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
        $headers .= 'From: info@hia.com'; 
        $send = mail($to, $subject, $msg, $headers);
        if($send){
            echo "successful";
        }
        else{
            echo "error";
        }
</div>
  • 写回答

2条回答 默认 最新

  • dongtou9934 2016-06-27 10:39
    关注

    Don't use simple mail(), i prefer for PHPmailer function. Here is a Example. First - download phpmailer in your project directory. second - create send_mail.php in your directory(you can change you name).

    • send_mail.php file code.

      require_once "PHPMailer/PHPMailerAutoload.php";
      
      $mail = new PHPMailer(true);
      if (!isset($_POST['send'])) {
      //This page should not be accessed directly. Need to submit the form.
      echo "error; you need to submit the enquiry form!";
      die;
      }
          $to="abc@xyz.com";
          $senderName = "xyz";
          //send the mail
          $fname = $_POST["fname"];
          $lname = $_POST["lname"];
          $zcode = $_POST["zcode"];
          $email = $_POST["email"];
          $phone = $_POST["phone"];
          //Enable SMTP debugging.
          $mail->SMTPDebug = 0;
          //Set PHPMailer to use SMTP.
          $mail->isSMTP();
          //Set SMTP host name
          $mail->Host = "smtp.gmail.com";
          //Set this to true if SMTP host requires authentication to send email
          $mail->SMTPAuth = true;
          //Provide username and password
          $mail->Username = "abc@xyz.com";
          $mail->Password = "########";
          //If SMTP requires TLS encryption then set it
          $mail->SMTPSecure = "ssl";
          //Set TCP port to connect to
          $mail->Port = 465;
          $mail->From = $to;
          $mail->FromName = $senderName;
          $mail->addAddress($to, $senderName);
          $mail->addReplyTo($email, $name);
          $mail->isHTML(true);
          $mail->Subject = "bfuiebfiaif";
          $mail->Body = "as per your needs";
      if (!$mail->send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
      die;
      }
      header('Location: index.php');
      die;
      
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化