- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Quick question for you guys, I have a fairly simple contact form (php obviously) that sends off an email upon completion of the form. However in the interest of good UX and UI, I have made an html email template with my client’s logo and colors—all that jazz. So instead of using the mail() method, is there a command I can send to my server that says, “hey ‘fancy-custom-email.html’ go to this person’s inbox?” seeing past the humor, is there any documentation or just straight up advice you guys can lend me? Let me know if I am not being very clear. I will try my best to clear it up.
-Matt
I would suggest using something like PHPMailer instead of the build-in mail() function. It will save you from a lot of headaches. So, based on the example on its readme file, after replacing the configuration values with your own, you’ll pass the whole html email that you want to send, to the $mail->Body
variable.
For example, if your html template is the following:
<h1>This is my HTML email</h1>
<p>I can use <strong>any tag</strong> I want</p>
You’ll end up with:
$mail->Body = '<h1>This is my HTML email</h1>
<p>I can use <strong>any tag</strong> I want</p>';
mail
will send HTML emails just fine (though you’re right that it is not the best solution). You simply need to add the proper headers.
$headers = "From: [email protected]\r\n"
. "MIME-Version: 1.0\r\n"
. "Content-type: text/html; charset=utf-8\r\n";
mail( $to,$subject,$body,$headers );
You should look into other email packages, though, especially if you need to do anything more complex (e.g., multiple or frequent emails; attachments, etc.).
(having trouble posting this. please accept my apologies this double-posts.)