Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
10-15-2009, 05:00 PM #1
- Join Date
- Oct 2009
- Thanked 0 Times in 0 Posts
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
// 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: email@example.com\n";
$headers .="Reply-To: firstname.lastname@example.org";
//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, 05:21 PM #2
- Join Date
- Dec 2005
- Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
- Thanked 637 Times in 625 Posts
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.
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.