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 = "myemail@gmail.com";
$mail->Password = "xxxxxx";

$mail->AddAddress("mymail@gmail.com");
$mail->From = "mymail@gmail.com";
$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: blank@blank.com Comments: I like soda!

 

where I would rather have something like:

 

Name: Bob

Email: blank@blank.com

Comments: I like soda!

 

Any advice would very much appreciated!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.