Page 1 of 1

adding attachment to email form backend

Posted: Sun Mar 02, 2008 3:34 am
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

Re: adding attachment to email form backend

Posted: Sun Mar 02, 2008 4:59 am
by Chris Corbyn
Don't use mail() for this. Use Swift Mailer which is what it does well :)

http://swiftmailer.org/