07 Enabling the Contact Form

  • id: contact

  • Section number: 07

  1. This project uses Composer for dependency management and PHPMailer for handling email sending in the contact form. Ensure the vendor/ directory contains the PHPMailer library.

  2. Store sensitive data (e.g., email credentials) in the .env file located in the env/ folder. Use the following format:

SMTP_HOST=smtp.gmail.com
SMTP_USER=your-email@example.com
SMTP_PASS=your-email-password
SMTP_SECURE=tls
FROM_EMAIL=your-email@example.com
FROM_NAME="Your Name or Portfolio Name"
  1. Understanding SMTP_SECURE

    The SMTP_SECURE variable specifies the encryption protocol for securing the connection to the SMTP server. Common values include:

    • tls: Recommended for most servers, including Gmail, as it provides strong encryption while using the default SMTP port (587).

    • ssl: Uses a different port (usually 465) and provides an additional layer of encryption during the connection.

    Using the correct encryption type is crucial for establishing a secure connection with the SMTP server. Always confirm the required protocol with your email provider.

  2. Generate SMTP Password: For Gmail users, generate an App Password to use as SMTP_PASS instead of your primary email password. For other email providers, follow their guidelines for generating secure credentials

  3. Edit Configurations: Update the send_email.php script to load the .env file and retrieve the credentials securely as well as edit the body of the email ($email_body) if you wish:

  1. Test the Form (Running the Project Locally)

If your project is not yet deployed online, you can run it locally using one of the following methods:

  1. Using XAMPP:

    • Place the project folder inside the htdocs directory of XAMPP.

    • Start Apache and MySQL from the XAMPP control panel.

    • Access your project in the browser using the URL: http://localhost/<your-project-folder>/public

  2. Using PHP's Built-in Server:

    • Navigate to the public folder of your project in the terminal.

    • Start the server with the command:

    • Open your browser and navigate to: http://localhost:8000

Last updated