Jump to content

How to stylize form output in emails


Drding

Recommended Posts

Hello all!

 

First, I'm a complete noob when it comes to php coding so bare with me on this. I know this might seem like a super simple thing to do, but as I said I'm a beginner at best.

 

What I have is a very simple contact form with three fields: name, email, and comments. The way I have it set up is that when someone fills out the form and hits the submit button, it sends me an email via Gmail with the values of the form. Pretty basic stuff.

 

The thing is, when I get the values in the email, it's all on one line and rather unflattering looking. It works for just me, I don't care really. But I'd like to turn around and use this form/php code I have for a client. The form for them is going to have a lot more input fields and I can only imagine the string of text that it's going to create.

 

What I would like to do is format the values that I or they receive via email so that it's a bit more presentable.

I have no idea how to do this.

 

Here's my php code connected to my form:

 

<?php

include_once("phpmailer/class.phpmailer.php");

$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments']; 

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";

$mail->SMTPSecure = "ssl";
$mail->Port = 465;

$mail->Username = "[email protected]";
$mail->Password = "xxxxxx";

$mail->AddAddress("[email protected]");
$mail->From = "[email protected]";
$mail->FromName = $_POST['name'];
$mail->Subject = "User Comment";
$mail->IsHTML(true);
$mail->Body = "Name: $name\n Email: $email\n Comments: $comments";


if($mail->Send()) {
   echo "Message sent! Thanks for your comments!";
} 
?>

 

so right now with that I get an email for example that looks like this:

 

Name: Bob Email: [email protected] Comments: I like soda!

 

where I would rather have something like:

 

Name: Bob

Email: [email protected]

Comments: I like soda!

 

Any advice would very much appreciated!

Link to comment
https://forums.phpfreaks.com/topic/222859-how-to-stylize-form-output-in-emails/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.