Sending HTML form to Mail by PHP

I am trying to send a an HTML form entry via mail using PHP. I have tried but it is not working.
Below is my HTML code:

<form action="assets/php/consultationmail.php" method="post">
<div class="input-field">
<input type="text" name="name" placeholder="Full Name" required>
<div class="input-field">
<input type="email" name="email" placeholder="[email protected]" required>
<div class="input-field">
<input type="tel" name="Phone" placeholder="0245678910" required>
<div class="input-field">
<input type="textarea" name="message" placeholder="Message" required>
<div class=" input-field">
<button type="submit" value="submit" class="template-btn">Get Consultations
<i class="far fa-long-arrow-right"></i></button>

And here’s is the PHP Code I added

$email_from='[email protected]';
$email_subject='New Consultation Request';
$email_body='A visitor has request for a consultation.<br>Details are below<br>Name:'.$name.'<br>Email:'.$email.'<br>Phone:'.$phone.'<br>Message:'.$message.'<br>';
$to='[email protected]';    

What am I doing wrong, please?

I would use Swiftmailer (This is what I use - Swift Mailer: A feature-rich PHP Mailer – Documentation – Swift Mailer) or PHPMailer to send HTML as it is much simpler →

        /* Setup swiftmailer using your email server information */
        $transport = (new Swift_SmtpTransport('', 587, 'tls'))
            ->setUsername("[email protected]")

        // Create the Mailer using your created Transport
        $mailer = new Swift_Mailer($transport);
        /* create message */
        $message = (new Swift_Message('Verification of Account'))
            ->setFrom(['[email protected]' => 'John Smith'])
            ->setTo([$data['email'] => $data['name']])
            ->setBody($data['message'], 'text/html')
            ->attach(entity: Swift_Attachment::fromPath(''));

        /* Send the message */
        return $mailer->send($message);

LOL - I just found out Swift Mailer isn’t supported any longer → Sending Emails with Mailer (Symfony Docs)

That doesn’t tell us anything. What exactly is “not working”? What exactly are the error messages? What do your error logs say?

Also, stop creating variables for nothing. Copying a variable to another variable without changing anything is pointless.

Sponsor our Newsletter | Privacy Policy | Terms of Service