Sending attachements over php

Reply

Join Date: Jun 2005
Posts: 44
Reputation: namit is an unknown quantity at this point 
Solved Threads: 0
namit namit is offline Offline
Light Poster

Sending attachements over php

 
0
  #1
Jun 25th, 2005
I have the following code

How do i first edit this to take errors and also to be able to attach files.

[PHP]
<?php
//Gets these from page before
$mail_ref = $_GET['mail_ref'];
$mail_title = $_GET['mail_title'];
$mail_location = $_GET['mail_location'];

?>

<title>RFC Job Application</title>

<link rel='stylesheet' href='../../rfcStyle.css' type='text/css'>
</head>
<body bgcolor='#ffffff' leftMargin='0' topMargin='6' marginheight='0' marginwidth='0'>
<table cellspacing='0' border='2' cellpadding='0' align='center' width='620' bordercolor='#000080'>
<tr>
<td class=bar><table width='97%' align='center' cellspacing='0' cellpadding='0' border='0'>
<tr>
<td class='banner' nowrap>RFC Recruitment Group</td>
<td class='banner' nowrap align='right'>Management & Professional Recruitment</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src='../../images/titleRfc.gif' width='185' height='70'></td>
</tr>
<tr>
<td class=title><img src='../../images/imgJobApplication.gif' width='295' height='33'></td>
</tr>
<tr>
<td align='center'>


<!-- START OF FORM -->
<form ACTION="sendmail.php" METHOD=POST align='center'>
<table cellspacing='2' cellpadding='2' border='0' width='100%' bgcolor=#ffffff>
<tr class=content2>
<td class='heading'>Ref No.</td>
<td class='heading'>Job Title</td>
<td class='heading'>Location</td>
</tr>
<tr class=content2>
<td><input name='mail_ref' value="<? echo $mail_ref ?>" type='text' size='20' style='width: 180px; height: 22px;'></td>
<td><input name="mail_title" value="<? echo $mail_title ?>" type='text' size='20' style='width: 180px; height: 22px;'></td>
<td><input name='mail_location' value="<? echo $mail_location ?>" type='text' size='20' style='width: 180px; height: 22px;'></td>
</tr>
<tr>
<td colspan=3 class='title' height=20 valign='center' align='center'>Your Details&nbsp;&nbsp;&nbsp;&nbsp;<font class=content3>(* Required Information)</font></td>
</tr>
<tr>
<td class='heading'><font class='content3'>*</font> Your Name</td>
<td class='heading'>Email Address </td>
<td class='heading'>Phone No.</td>
</tr>
<tr>
<td><input name='mail_Name' tabindex='1' type='text' size='20' style='width: 180px; height: 22px;'></td>
<td><input name='mail_Email' tabindex='2' type='text' size='20' style='width: 180px; height: 22px;'></td>
<td><input name='mail_Tel' tabindex='3' type='text' size='20' style='width: 180px; height: 22px;'></td>
</tr>
<tr>
<td class='heading'><font class='content3'>*</font> Contact Address</td>
<td class='heading' colspan='2'>Additional Comments</td>
</tr>
<tr>
<td>
<textarea name='mail_Contact' tabindex='4' style='width: 180px;' cols='20' rows='4' wrap='physical'></textarea></td>
<td colspan='2'><textarea name='mail_Comments' tabindex='5' rows='4' style='width: 360px;' cols='40'></textarea></td>
</tr>
<tr>
<td colspan='3' align='center' valign='center' height='50'>&nbsp;
</td>
</tr>
<tr>
<td colspan='3' align='center' valign='center' height='50'><input name="submit" type='submit' tabindex='6' value=' Send Application '></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td class=bar height='15' align='center'>
<a class=headlink href='javascript:window.close();'>Close Window</a></td>
</tr>
</table>
</body>
</html>
<?


//////////////////////////PAGE 2

//first_mail.php
$mail_to = "bla@bla.com";
//$mail_subject = "Hi there";

$mail_ref = $_POST['mail_ref']; //Subject
$mail_title = $_POST['mail_title']; //Job Title
$mail_location = $_POST['mail_location']; //Location
$mail_Name = $_POST['mail_Name']; //Name
$mail_Email = $_POST['mail_Email']; //Email address
$mail_Tel = $_POST['mail_Tel']; //Tel number
$mail_Contact = $_POST['mail_Contact']; //Contact details
$mail_Comments = $_POST['mail_Comments']; //Comments

///MAin Body :::
$mail_body = "Location: $mail_location \n Job Title: $mail_title \nName: $mail_Name \nEmail: $mail_Email \nTel: $mail_Tel \nContact: $mail_Contact \nComments: $mail_Comments \n";
?>
[/PHP]
Attached Files
File Type: php sendmail.php (2.3 KB, 15 views)
File Type: php apply.php (3.6 KB, 11 views)
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 514
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: Sending attachements over php

 
0
  #2
Jun 25th, 2005
I am not going to fix your code for you.

If I do .. you will never learn anything form it.

But have a look at this:

  1.  
  2. How to add multiple attachment to an email:
  3.  
  4. An email can be split into many parts separated by a boundary followed by a Content-Type and a Content-Disposition.
  5.  
  6. The boundary is initialized as follows:
  7. <?php
  8. $boundary = '-----=' . md5( uniqid ( rand() ) );
  9. ?>
  10.  
  11. You can attach a Word document if you specify:
  12. <?php
  13. $message .= "Content-Type: application/msword; name=\"my attachment\"\n";
  14. $message .= "Content-Transfer-Encoding: base64\n";
  15. $message .= "Content-Disposition: attachment; filename=\"$theFile\"\n\n";
  16. ?>
  17.  
  18. When adding a file you must open it and read it with fopen and add the content to the message:
  19. <?php
  20. $path = "whatever the path to the file is";
  21. $fp = fopen($path, 'r');
  22. do //we loop until there is no data left
  23. {
  24. $data = fread($fp, 8192);
  25. if (strlen($data) == 0) break;
  26. $content .= $data;
  27. } while (true);
  28. $content_encode = chunk_split(base64_encode($content));
  29. $message .= $content_encode . "\n";
  30. $message .= "--" . $boundary . "\n";
  31. ?>
  32.  
  33. Add the needed headers and send!
  34. <?php
  35. $headers = "From: \"Me\"<me@here.com>\n";
  36. $headers .= "MIME-Version: 1.0\n";
  37. $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
  38. mail('myAddress@hotmail.com', 'Email with attachment from PHP', $message, $headers);
  39. ?>
  40.  
  41. Finally, if you add an image and want it displayed in your email, change the Content-Type from attachment to inline:
  42.  
  43. <?php
  44. $message .= "Content-Disposition: inline; filename=\"$theFile\"\n\n";
  45. ?>

This should give you everything you need to fix your own issue.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 44
Reputation: namit is an unknown quantity at this point 
Solved Threads: 0
namit namit is offline Offline
Light Poster

Re: Sending attachements over php

 
0
  #3
Jun 25th, 2005
Go on you know you want to fix it for me at least show me how to put one if statement in it to check if the fields are filled in properly.

Thank you
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 44
Reputation: namit is an unknown quantity at this point 
Solved Threads: 0
namit namit is offline Offline
Light Poster

Re: Sending attachements over php

 
0
  #4
Jul 6th, 2005
Thank you for your help got it done it was not that hard.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 514
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: Sending attachements over php

 
0
  #5
Jul 6th, 2005
My Pleasure
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC