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 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率