Send form data with PHP Mailer without entering an email address in the form?

Hello,

I want to send a form for private purposes, but without including an email address in the form. As far as I can remember, you could assign the corresponding email address to the code in the editor, and all form data would be automatically sent to it.

I would be very grateful if you could help me 🙏

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
4 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Innowise
1 year ago

Of course, I can help you create a form that sends data with PHP mailer without the recipient’s email address being visible in the form itself. Instead, the recipient’s email address is set directly in the PHP code that processes the form. Here is a basic example of how you can do this:

Step 1: Create your HTML form

First create your HTML form without a field for the email address. Here is a simple example:

html

Copy code




Step 2: Edit and send data with PHP mailer

Create a PHP file (in this example)

sendmail.php

), which processes the data of the form and sends it with PHP mailer. You need to install PHP mailers in your project if you haven’t done this yet. You can install PHP mailers with Composer or integrate the required files directly into your project.

Here is a simple example for

sendmail.php

:

php

Copy code
SMTPDebug = SMTP::DEBUG_SERVER; // Aktivieren Sie diese Zeile für detaillierte Debug-Ausgaben $mail->isSMTP(); $mail->Host = 'smtp.example.com'; // Setzen Sie hier Ihren SMTP-Server $mail->SMTPAuth = true; $mail->Username = 'your-email@example.com'; // SMTP-Benutzername $mail->Password = 'your-password'; // SMTP-Passwort $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 587; //Empfänger $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('empfaenger@example.com'); // Fügen Sie hier die Empfänger-Adresse hinzu //Inhalt $mail->isHTML(true); $mail->Subject = 'Neue Nachricht von Ihrem Formular'; $mail->Body = 'Name: ' . $_POST['name'] . '
Nachricht: ' . $_POST['message']; $mail->send(); echo 'Nachricht wurde gesendet'; } catch (Exception $e) { echo "Nachricht konnte nicht gesendet werden. Mailer Error: {$mail->ErrorInfo}"; } ?>

In this PHP script:

  • Replace
  • path/to/PHPMailer/src/...
  • with the actual path to the PHPMailer files in your project.
  • Configuring The
  • $mail->Host
  • ,
  • $mail->Username
  • ,
  • $mail->Password
  • and other settings according to your email server.
  • The recipient’s e-mail address will be
  • $mail->addAddress('empfaenger@example.com');
  • set.

When the form is sent, the data will be sent to

sendmail.php

sent, and the PHP script uses PHP mailer to send the data to the specified email address without the email address appearing in the form itself.

https://innowise.com/en/php-development services/

regex9
1 year ago

The PHPMailer-Instance, you can use the recipient address AddAddress– Provide method. See the example on the GitHub page of PHPMailer on.