2

I'm in over my head here, and even being pointed to the right pages on this site would be extremely helpful because everything I've found might as well be in Chinese. (I learned enough PHP and JQuery to get this right so far, and that is the limit of my knowledge on either of those.)

I have a form in HTML that utilizes JQuery. The user selects the options they want and the total price of everything they've selected is given at the bottom. I finally got all of this to be sent to a PHP page that lists only the options they selected along with the total of the selected options (a major victory for me).

As of right now, the page can be printed. But I need the entire PHP page (preferably with the same format, but whatever, as long as it includes the data that was created) to be emailed both to my company's email address AND to an address that the user enters. So obviously, I need a text box, but I'm clueless how to send the results.

I'm so sorry if this is already on the site somewhere- I'm sure it is, but it's just not making sense to me right now, and I've been attempting this one for quite awhile.

Here's the form as it stands so far: http://f650pickups.com/buildform.html

Lynzi
  • 31
  • 1
  • The usual way is to use something like [fpdf](http://www.fpdf.org/) and send a PDF invoice using PHP's [mail()](http://php.net/manual/en/function.mail.php) function to send the email, and that of course requires that the server is set up with a mail program of some sort. – adeneo Nov 17 '13 at 15:30

2 Answers2

0

Not a complete answer, but when you get going, I suggest you use an existing SMTP server like this answer suggests:

Send email using the GMail SMTP server from a PHP page

SMTP servers can be very difficult for beginners to setup and it doesn't sound like an appropriate tool from your question.

I pre-emptively pose this response because most beginners guides to email through PHP require that you have your own local SMTP server set up and running. As I said, that is very difficult. Using Gmail, or something similar, is generally an easy way of accomplishing your goal.

Community
  • 1
  • 1
eatonphil
  • 13,115
  • 27
  • 76
  • 133
0

You have two questions here. The first is how to send e-mail with PHP. That is commonly done with the mail() function.

Your second question is about sending HTML e-mail with PHP. This is where e-mail gets really complicated, making the mail() function almost completely useless to you.

Any type of e-mail beyond text requires complex multi-part MIME messages. Do not code these yourself, there is no point. Instead, use an e-mail class of the shelf that does it for you. There are many to choose from. I recommend PHPMailer.

If you have the following to echo out a form choice:

echo '<input type="text" value="' . htmlspecialchars($userInputValue) . '" />';

You coluld change this to PHPMailer easily:

$mail = new PHPMailer();
$mail->isHTML(true);
$mail->Body = '<input type="text" value="' . htmlspecialchars($userInputValue) . '" />';

Basically, set the Body property to be whatever HTML you want to e-mail. Now, it is actually important to set $mail->AltBody with a plain-text version as well. Not all e-mail clients can render HTML, and many mobile devices will display message previews using the text version. This is rarely a problem these days, but it is best practice to still include the text version.

I recommend the full example e-mail: https://github.com/Synchro/PHPMailer#a-simple-example

Brad
  • 159,648
  • 54
  • 349
  • 530