How to send email to user input email address after click a submit button? In php

Apple Juice

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?

Peter G

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).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to send email on contact form submit button click..?

From Dev

How to send notification automatically to logged in user secondary email address in php?

From Dev

Trying to send an email in PHP only after the submit button is pressed and the form is valid

From Dev

How to send an email after User post the form?

From Dev

Send email on html button click

From Dev

Rails - send email on button click

From Dev

Send Email After Button Click in ASP.net C#

From Dev

PHP send email to address entered by user in a plugin file

From Dev

How to validate email and password on click of submit button in React native?

From Dev

How to get php mail() to send user uploaded image to my email address

From Dev

How to get php mail() to send user uploaded image to my email address

From Dev

How do I connect to the database, shoot and email and update database simultaneously when the user clicks the submit button in PHP?

From Dev

Send email to user after Registration

From Dev

Make a submit button send email with details in HTML

From Dev

Use Submit button to send form data to an email

From Dev

how to Send the user to another activity after a email is send

From Dev

PHP send email foreach user

From Dev

How to link a button to an email address

From Dev

How to prompt the user to input the correct format of email address in C++?

From Dev

Send as alternative email address for same user

From Dev

Can app send email without letting the user know the email address?

From Dev

How to send email to selected email in php

From Dev

WebApi how to send asyncronous email after returning response to user?

From Dev

PHP Send email to multiple address from SQL

From Dev

How do I retrieve user email from Firebase Firestore and send it to an email intent when a button is clicked?

From Dev

How to send email to all user with condition using php laravel?

From Dev

How to track link click in email sent to user with php mail function

From Dev

How to track link click in email sent to user with php mail function

From Dev

Active Collab send Email after User create

Related Related

  1. 1

    how to send email on contact form submit button click..?

  2. 2

    How to send notification automatically to logged in user secondary email address in php?

  3. 3

    Trying to send an email in PHP only after the submit button is pressed and the form is valid

  4. 4

    How to send an email after User post the form?

  5. 5

    Send email on html button click

  6. 6

    Rails - send email on button click

  7. 7

    Send Email After Button Click in ASP.net C#

  8. 8

    PHP send email to address entered by user in a plugin file

  9. 9

    How to validate email and password on click of submit button in React native?

  10. 10

    How to get php mail() to send user uploaded image to my email address

  11. 11

    How to get php mail() to send user uploaded image to my email address

  12. 12

    How do I connect to the database, shoot and email and update database simultaneously when the user clicks the submit button in PHP?

  13. 13

    Send email to user after Registration

  14. 14

    Make a submit button send email with details in HTML

  15. 15

    Use Submit button to send form data to an email

  16. 16

    how to Send the user to another activity after a email is send

  17. 17

    PHP send email foreach user

  18. 18

    How to link a button to an email address

  19. 19

    How to prompt the user to input the correct format of email address in C++?

  20. 20

    Send as alternative email address for same user

  21. 21

    Can app send email without letting the user know the email address?

  22. 22

    How to send email to selected email in php

  23. 23

    WebApi how to send asyncronous email after returning response to user?

  24. 24

    PHP Send email to multiple address from SQL

  25. 25

    How do I retrieve user email from Firebase Firestore and send it to an email intent when a button is clicked?

  26. 26

    How to send email to all user with condition using php laravel?

  27. 27

    How to track link click in email sent to user with php mail function

  28. 28

    How to track link click in email sent to user with php mail function

  29. 29

    Active Collab send Email after User create

HotTag

Archive