Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Encoded Email-order confirmation

A customer orders something in a shop, like (shirts4Mike), after finishing the order, (The information will eb saved in the Database-after that) he shoud get a order confirmation with all his order information in a encoded Mail

How to create that ?Can someone help please? Thank you.

5 Answers

What do you mean by encoded email order confirmation? Can you please be more specific and I can try to help... Generally you would either do it with PHP's standard mail function (scroll to the bottom of http://ch1.php.net/manual/en/function.mail.php for examples) or with a specialized class like https://github.com/PHPMailer/PHPMailer that gives your more flexibility. But maybe I am misunderstanding your question.

Greetings from Biel to Seedorf ;-)

At a successful order the customer shall receive a order confirmation by mail with his order number.

And it should be made followingly:

If the information (order) is written successfully in the database, it shall produce a random number key and send this(order confirmation data)with a link by mail to the cusomer again .

How shall we proceed here?Can someone help. Thanks

strictly doing what you are describing, without questioning ;-)

EDIT: I deleted the code as it didn't format properly. you can fetch it here: http://codepad.org/cSmqjmag

the above is the most basic way of executing exactly what you are describing. some remarks:

  1. you would probably want to generate the order number earlier and write it to the database along with the other information

  2. by generating a random number you cannot be sure that it will be unique, so you either need to make sure it doesn't exist already when writing to the database or even better: use auto-incrementing order numbers

  3. sending emails like this (right from the server) may have your email end up in the customers' spam folder or even be rejected by the server. it's much better to send e-mails via a "real" e-mail account. Assuming you are a native german speaker, here is a tutorial to a more robust email implementation using the PHPMailer class: http://mailinfo.kundenserver.de/auth_phpmailer.php3

  4. I haven't tested the code above, so there may be typos :-)

Thank you vey much for the answer-I will try it Hope it works!

I don't seem to be able to format stuff nicely here, so I pasted the code on codepad for you to copy:

http://codepad.org/cSmqjmag

Good luck!