If you ever played around with the native PHP mail function, you will probably know that it’s functionality is very basic. Plain text emails work great, but if you want to do HTML email, you need to figure out what mail headers to send with your message. And if you want to send an attachment you need to base64 encode it yourself.
Good news is that you only need to implement it once. Even better news is, that almost every PHP developer out there already implemented their own email class at one point or another. Therefore, you should not be wasting time on this – just go out there and steal some code.
If you are shopping around for a good PHP email functionality I recommend PHPMailer. Why do I like it? Let me count the ways:
- Easy to use
- No Setup involved – just drop the class files in your include path
- Let’s you sen attachments, html emails and etc without any thinking
- Works with PHP4
- Widely used (included in projects like Mambo, Moodle, PostNuke, Xoops and etc..
- Well documented
- Distributed under GPL
How easy to use is it? Let me show you. Here is a simple script that will send an email with an attachment:
From = "you@example.com";
$mail->FromName = "Your Full Name";
$mail->Host = "smtp.example.com";
$mail->Mailer = "smtp";
$mail->AddAddress("someone@example.com");
$mail->AddCC("supervisor@example.com");
$mail->AddBCC("secret@example.com");
$mail->Subject = "This is Your Subject";
$mail->Body = "This is your message";
$mail->AddAttachment("~/files/something.zip", "new_name.zip"); // optional name
if(!$mail->Send())
{
echo "There was an error sending the message";
exit;
}
echo "Message was sent successfully
";
?>
How is that for simple? It’s a piece of cake! I have been using it for a while now, and I haven’t had any problems with it. So go and steal it today.
[tags]php, phpmailer, mail, php email, php email attachments, attachment[/tags]
I have been wanting to do this for a while… now all i need is a way to upload the file and then have the uploaded file emailed.
Want to hear my idea? I don’t care if someone steals it I said it here first we all know its my idea and if someone steals it they are just a dirty bastard and we all know who the smart guy is.
Annon. Youtube videos:
Some videos you want to post but you don’t want to put your name to it or something. You can upload it with the site i make, and it will be emailed off and eventually approved maybe. I am thinking of an approval system though, as to stop like porn and stuff.
Well, file uploads in php are easy. The only problem with this is that movie files tend to be big. Email is just not the best medium for shipping around files few hundred megs in size.
Btw, what’s wrong with creating a one-use-only Youtube account for the purpose of posting something?
I every time emailed this webpage post page to all my
associates, as if like to read it next my contacts will too.