Sending email from your website with PHP
Written by Joe on Thursday, January 28, 2010
Sending email from your website can be a very useful feature. When a user makes a purchase, fills out a form, forgets a password; being able to send them an automated email adds value to your website. In this article I will go over how to send an email using PHP.
In PHP, the mail() function is used to send emails. The mail function takes four parameters:
- to email
- email subject
- email message
- additional headers
Simple right? The to email is the recipient you would like to send the email to. Email subject is the subject the user first sees when recieving the email. The message is the content of the email, which can be plain text or HTML. Additonal headers can be anything from, a from email address, reply-to email address, carbon copy email address, blind carbon copy email and more.
Here is a simple example with no additional headers:
$to = 'email@domain.com';
$subject = 'My Email Subject';
$message = 'Thank you for filling out our form';
mail($to,$subject,$message);
Here is another example using some additional headers:
$headers .= 'To: Jane <jane@example.com>, Kim <kim@example.com>' . "rn";
$headers .= 'From: My Website <info@example.com>' . "rn";
$headers .= 'Cc: joe@example.com' . "rn";
$headers .= 'Bcc: mike@example.com' . "rn";
$to = 'email@domain.com';
$subject = 'My Email Subject';
$message = 'Thank you for filling out our form';
mail($to,$subject,$message,$headers);
As you can see, sending email messages using php is very simple. There is much more you can do, including sending HTML emails. Click here to read part two "Sending HTML emails from your website with PHP".
Like what you’ve read?
Link back to us.
http://www.revolutionunlimited.com/news-and-articles/php/2010-01-28/sending-email-from-your-website-with-php/
OR Join Our Mailing List
Want to drive more traffic to your website?Our results driven search engine optimization services will get you the results you want. Contact Us Today |
![]() |
News And Articles
Get A Free Quote
Looking For Something?
Get a FREE website consultation!
* indicates required fields
Testimonials
I'm liking how easy this is...I've never had a web site project go so smoothly. Thank you for that and I do look forward to a long... Read More »
Wow! The website looks Great! Thanks Joe. I'm very happy with Revolution Unlimited & I am going to recommend you to all of my friends !... Read More »
It is my pleasure to recommend Mr. Joe Brown whose native intelligence for web designing is great. Joe's dedication to the A... Read More »
We at The Ale House Tavern & Tap, based out of Sayreville, are very pleased with the work that PixelProgression and Revolution Unlimited put... Read More »
I had the great fortune of connecting with PixelProgression and Revolution Unlimited when I decided there was need for a new website. This website... Read More »
As a nonprofit organization, we needed the assistance of a website designer who was knowledgeable, affordable, easily accessible, patient and,... Read More »
Pennsylvania Dutch Design would like to commend Jason of Pixel Progression and Joe of Revolution Unlimited. With their extensive knowledge... Read More »






Post A Comment