Help sending full html email response using php form

Hi all

I’m working on a basic html php form which collects data, validates, and then sends a small message to the collected email address once submitted and stored in the database, working good.

The snippet I need help with is below. Instead of sending a small message, I need to some how send a full html email to the email address I collected. Using the data below, how would I do that?

Is it possible to send email-template.html as the message, what is the best way?

// No errors, email the details
if (strlen($s_error_message) == 0)
{
    $to="barry@example.com";
    $message = "Sender: " 
        . $first_name . ' ' 
        . $surname . "\n" 
        . $email . "\n\nPlease send my colleague, " 
        . $colleagues_first_name . ", a Email.\n" . $colleagues_email;
    $subject = "Please send my colleague an email";
            
    if (mail($to, $subject, $message, 'From: ' . $email)) {header('Location: https://example.com');}
    else {print('There was a problem sending the mail. Please check that you filled in the form correctly.');}
}

Thanks, Barry

Perhaps this can be helpful?

1 Like

Thanks Ryan

Its not the html email I need, I already have the email template in place ready to send. I need to somehow attach this email to the form and send it as the response instead of the small message in the code shown above.

I also need to add both $colleagues_email and $colleagues_name into this template so they are greeted by name.

Does this make sense?
What do you suggest, anyone?

Thanks, Barry

This might be useful.

Exactly that! Cool :smile:

This gives me a good starting point anyway, a few php tags I’m unfamiliar with though I’ll have a quick google. I basically have a full html page with css and responsive layout, I’ll need to somehow incorporate this into the method you have shown.

The best so far Ryan… on the right track thank you!
I’ll report back with any problems.

Barry