Jump to content

How to send an email automatically


pwired
 Share

Recommended Posts

Hi,

I am making a very simple webshop with processwire. I am not going to use paypal

and also not credit cards, but simple bank transfers and emailing with the customers.

I know how to make a form on a website that somebody can fill in

and then will be send to an email address.

But when a customer buys a product on a website made with processwire,

how can I make processwire send an email automatically to this customer

to confirm his order ? I just need something simple. Thanks.

Link to comment
Share on other sites

You can use PHP's default mail function:

$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers); 
 

But personally I would recommend installing the free SwiftMailer class (swiftmailer.org). It is incredibly powerful and can easily send mail using SMTP, can include both HTML and plain text versions in the one send, allow you to add attachments which is great if you are using a PHP PDF generating class to automatically generate a receipt, and lots more!

  • Like 2
Link to comment
Share on other sites

Thanks for the quick reply and the link to swiftmailer.

When a customer selects a product on a webpage that he wants to buy,

from that point on how do I trigger the event that an email is send to the customer.

Maybe in a simple way with the api or fields within processwire ?

Link to comment
Share on other sites

Well there are lots of options here, but based on your first post it sounds like you'll be having them submit a form and then send the email, so all you need to do is include the code to send the email in the script that processes the form submission, which would then presumable redirect to another page to say their order/payment has been received.

You could also send an email via an AJAX call. Lots of options, but if you have a more detailed question, let us know.

You could certainly use a PW field, or a series of fields to contain the various components of the email so these are editable by your site authors.

Hope that helps.

Link to comment
Share on other sites

Your reply has brought me a simple idea. When a client wants to buy a product and clicks on a buy button underneath this product, I can use this button click to link to a form where the client can fill in his data such as his email. Also I can use the fields inside PW where the product data is and use the contents of these fields to be used on the form. What you think, will this work ? Thanks.

Link to comment
Share on other sites

Sounds like a good solution to me - the only thing you should need to pass to the form is the ID of the product (and maybe the number of them they are buying). You can grab all the other details via the PW API once you are at the form - you can even echo these out above the form so the user is sure of what they are buying. Then you can send these details to the form submission processing script to be used in the email via hidden form fields, or just get those details again from the product ID.

If you are building a shopping cart with multiple items, then obviously you'll want to make use of cookies to store the product IDs and the number they are buying. Then the form script would read the cookies.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...