douxian4376 2018-05-14 09:07
浏览 62
已采纳

单击提交按钮后如何向用户输入的电子邮件地址发送电子邮件? 在PHP中

I'm super new at coding. This is the form page code

<?php
// Start the session
session_start();
?>
<!DOCTYPE HTML>  
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>  

<?php
$fnameErr = $emailErr = $addressErr = $countryErr = $stateErr = $suburbErr = "";
$fname = $email = $address = $country = $state = $suburb = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["fname"])) {
    $fnameErr = "Name is required";
  } else {
    $fname = test_input($_POST["fname"]);
  }
  
  if (empty($_POST["email"])) {
    $emailErr = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
  }
    
  if (empty($_POST["address"])) {
    $addressErr = "Address is required";
  } else {
    $address = test_input($_POST["address"]);
  }

  if (empty($_POST["country"])) {
    $countryErr = "City is required";
  } else {
    $country = test_input($_POST["country"]);
  }

  if (empty($_POST["state"])) {
    $stateErr = "State is required";
  } else {
    $state = test_input($_POST["state"]);
  }
  
  if (empty($_POST["suburb"])) {
    $suburbErr = "State is required";
  } else {
    $suburb = test_input($_POST["suburb"]);
  }
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

<h2 align="cemter">Check out</h2>
<p><span class="error">* required field</span></p>
  
  Full Name: <input type="name" name="fname">
  <span class="error">* <?php echo $fnameErr;?></span>
  <br><br>
  E-mail: <input type="email" name="email">
  <span class="error">* <?php echo $emailErr;?></span>
  <br><br>
  Address: <input type="text" name="address">
  <span class="error">*<?php echo $addressErr;?></span>
  <br><br>
  Country: <input type="text" name="country">
  <span class="error">*<?php echo $countryErr;?></span>
  <br><br>
  State: <input type="text" name="state">
  <span class="error">*<?php echo $stateErr;?></span>
  <br><br>
  Suburb: <input type="text" name="suburb">
  <span class="error">*<?php echo $suburbErr;?></span>
  <br><br>
  <form method="post" action="../mailer/index.php">
  <input type="submit" name="submit" value="Purchase"> 
  </form>
</body>
</html>

But after I fill up all the information and click submit, the page said cannot connect to SMTP sever host. The strange thing is, I can send email while run the phpmailer index.php alone. The form page php file and the mailer php file is in a different folder but same parent folder, is this the problem?

</div>
  • 写回答

1条回答 默认 最新

  • douniao7308 2018-05-14 11:42
    关注

    If one page works and another doesn't, and these are in different folders, then yes, that could be the problem. However, the solution is probably not to just move one of the files (which would probably give you other path related issues), but instead make sure that they both can reach the neccessary configuration (SMTP server host in this case).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制