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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵