Email with attachment

the mail() function

Moderators: macek, egami, gesf

longbo43
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jan 04, 2012 4:32 am

Email with attachment

Postby longbo43 » Thu Jan 05, 2012 6:37 am

I have the following code on my website that when a button is clicked it adds a new record into a MySQL database and also send an email with the new record information in the body of the email.

What I have done now is added a file upload box on the form and want to be able to add this uploaded file as an attachment to the email.

I need to either get the code for adding the attachment to the email or need pointers on how to get started.

Any help would be greatly appreciated.

Code: Select all

//**********  Send email with new data  ************

$email="test@test.com";
$from="admin@test.com";
$msg="";
$subject="New data record";

foreach($values as $field=>$value)
{
   if(!IsBinaryType(GetFieldType($field)))
      $msg.= $field." : ".$value."\r\n";
}
   
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
if(!$ret["mailed"])
   echo $ret["message"];



//**********  Send email with new data  ************

$email=$values["*******_Email"];
$from=$values["*******_Email"];
$cc="*******@**************.com";

$link = mysql_connect("www.**********.com", "********", "*********");
mysql_select_db("r******t_m*g", $link);
 
$result = mysql_query("SELECT * FROM meetingtooldata", $link);
$rows = mysql_num_rows($result);
$lastID=$rows + 1;
//$lastID=mysql_query($rows) + 1;


$msg="If you have any questions, please contact ***** ********* at ******@***************.com or by phone at +44 (0)**** ******.\n\nMeeting ID: $lastID.\n";
$subject="Meeting Request ID ".$lastID.", ".$values["Operator"].", ".$values["Target1_Contact_Surname"];

foreach($values as $field=>$value)
{
   if(!IsBinaryType(GetFieldType($field)))
      $msg.= $field." : ".$value."\r\n";
}
   
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from' => $from, 'cc' => $cc));
if(!$ret["mailed"])
   echo $ret["message"];




return true;

User avatar
bigjoe11a
New php-forum User
New php-forum User
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA
Contact:

Re: Email with attachment

Postby bigjoe11a » Sun Jan 29, 2012 6:29 pm

Do a search on google.com and look for phpmailer.php. This will make it easy for you to attach files in email messages. After you download it and if you have any problems with it. Let me know.

Joe


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest

cron