adding attachment to email form backend

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bloodl
Forum Commoner
Posts: 48
Joined: Thu Jun 21, 2007 12:33 am

adding attachment to email form backend

Post by bloodl »

I have a pretty simple email form, but I would like it to email an attachment that I specify myself each time. I'm not sure if its even possible?

Here is my code:

Code: Select all

<?php
$myemail = "me@myemailaddress.com"; 
 
$todayis = date("l, F j, Y, g:i a") ;
 
$name=$_REQUEST["name"];
$name=$_REQUEST["email"];
$name=$_REQUEST["enquiry"];
$name=$_REQUEST["how"];
$name=$_REQUEST["other"];
$name=$_REQUEST["message"];
 
 
$name=preg_replace("/\r/"," ",$name);
$name=preg_replace("/\r/"," ",$name);
$email=preg_replace("/\r/"," ",$email);
$email=preg_replace("/\r/"," ",$email);
$enquiry=preg_replace("/\r/"," ",$enquiry);
$enquiry=preg_replace("/\r/"," ",$enquiry);
$how=preg_replace("/\r/"," ",$how);
$how=preg_replace("/\r/"," ",$how);
$other=preg_replace("/\r/"," ",$other);
$other=preg_replace("/\r/"," ",$other);
$message=preg_replace("/\r/"," ",$message);
$message=preg_replace("/\r/"," ",$message);
 
 
$subject = "Online Enquiry from $_REQUEST[name] ";
 
$message = "$todayis [EST] \n
Name: $_REQUEST[name] \n
Email: $_REQUEST[email] \n
Enquiry: $_REQUEST[enquiry] \n
How did they find us?: $_REQUEST[how] \n
Other: $_REQUEST[other] \n\n
********************************************************
Message: $_REQUEST[message] \n
********************************************************
";
 
$from = "From: $_REQUEST[email] \r\n";
 
if ($myemail != "") 
mail($myemail, $subject, $message, $from);
 
?>
If I wanted to send an attachment to that, what would I add? Any help would be great - I am sorta new to this. I get the feeling that this form has unnecessary lines in it too?

Cheers,
Doug
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: adding attachment to email form backend

Post by Chris Corbyn »

Don't use mail() for this. Use Swift Mailer which is what it does well :)

http://swiftmailer.org/
Post Reply