View Full Version : php

10-15-2009, 06:00 PM
I am new to php, firstly what does php mean, secondly and more seriously I would like to know how to send a attachment as part of a mail using the mail function..

I copied the following code off the net it works but I dont know how to make it work to send an attachment to.

//define the receiver of the email
$to ="lawwz@hotmail.com";
// define the subject
$subject = "Testing mail function";
// define the message to be send each line should be separated with a \n
$message ="Hello there how are you\nfine thanks ";
//define the headers we want passed. Note they are separated with \r\n
$headers ="From: lawwz@hotmail.com\n";
$headers .="Reply-To: lawwz@hotmail.com";
//send the mail
$mail_sent = @mail[/B]($to, $subject, $message, $headers);
echo $mail_sent ? "Mail sent" : "Mail failed";

Also I get a waring with this code but if I change the last line to @mail instead of mail(...) it doesnt give the warning?

10-15-2009, 06:21 PM
The acronym PHP is recursive.. it stands for PHP Hypertext Preprocessor. Clever I know.

Anyways you should take a look at the manual, it has a nice little introduction to PHP and how it works. In the left column the question "What is PHP?" is asked and answered.


The "@" sign suppresses warnings and errors. It doesn't do anything to fix what's actually wrong, and makes it extremely difficult to troubleshoot and debug problems. It's a horrible way to "fix" crappy code. The _only_ reason to use it is if you are a terrible programmer who doesn't know how to code. :D

Sending attachments using the mail() function can be surprisingly challenging. It's definitely not a "beginner" task, but if you Google +php +email +attachment you'll find several tutorials on the subject.

My personal favorite way of doing it is by using a third-party open source package called PHP Mailer. Makes it pretty simple.