Current location: Hot Scripts Forums » Programming Languages » PHP » PHP to HTML email & attachment problem


PHP to HTML email & attachment problem

Reply
  #1 (permalink)  
Old 04-20-06, 10:51 AM
arandlett arandlett is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
PHP to HTML email & attachment problem

I have a form that is submitted which sends an HTML Email & and Attachment if added. However, the script Errors when no file is attached, but will send successfully when a file is attached.

Code:
$to = "name@name.com";
$department = $_REQUEST['department'];
$accNumber = $_REQUEST['accNumber'];
$todaysDate = $_REQUEST['todaysDate'];
$contactName = $_REQUEST['contactName'];
$contactEmail = $_REQUEST['email'];
$contactPhone = $_REQUEST['contactPhone'];
$dateNeeded = $_REQUEST['dateNeeded'];
$colors = $_REQUEST['colors'];
$paper = $_REQUEST['paper'];
$quantity = $_REQUEST['quantity'];
$designNotes = $_REQUEST['designNotes'];


$from =  $contactEmail;
$subject = "Graphic Service Request";

 $htmlVersion = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<style type='text/css'>
<!--
body {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	color: #000000;
}
.bottom_boarder {
	border-bottom-width: thin;
	border-bottom-style: solid;
	border-bottom-color: #666666;
}
.left_boarder {
	border-left-width: thin;
	border-left-style: solid;
	border-left-color: #999999;
}
h1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
	font-weight: bold;
	color: #000000;
}
.top_boarder {
	border-bottom-width: thin;
	border-bottom-style: none;
	border-bottom-color: #333333;
	border-top-width: thin;
	border-top-style: solid;
	border-top-color: #333333;
}
.style1 {color: #990000}
.style2 {color: #003366}
-->
</style>
</head>

<body>
<table width='1053' border='0' cellpadding='3'>
  <tr>
    <td colspan='4'><table width='1001' border='0' cellpadding='3' class='bottom_boarder'>
      <tr>
        <td width='30'><h1 align='right'>Job#:</h1></td>
        <td width='52'></td>
        <td width='111'><h1 align='right'>Ministry/Department:</h1></td>
        <td width='135'>".$department."</td>
        <td width='56'><h1 align='right'>Account#:</h1></td>
        <td width='81'>".$accNumber."</td>
        <td width='78'><h1 align='right'>Contact:</h1></td>
        <td width='121'>".$contactName."</td>
        <td width='115'><div align='right'>
          <h1>Contact Phone: </h1>
        </div></td>
        <td width='140'>".$contactPhone."</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan='4'><table width='1003' border='0' cellpadding='3' class='bottom_boarder'>
      <tr>
        <td width='44'><h1 align='right'>Date in: </h1></td>
        <td width='116'>".$todaysDate."</td>
        <td width='32'><h1 align='right'>Due:</h1></td>
        <td width='130'>".$dateNeeded."</td>
        <td width='62'><h1 align='right'>Completed:</h1></td>
        <td width='218'>&nbsp;</td>
        <td width='77'><h1 align='right'>Charge Date: </h1></td>
        <td width='258'>&nbsp;</td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan='4'><table width='1004' border='0' cellpadding='3' class='bottom_boarder'>
      <tr>
        <td width='69'><h1 align='right'>Assigned to: </h1></td>
        <td width='220'>&nbsp;</td>
        <td width='24'><h1 align='right'>PO#</h1></td>
        <td width='257'>&nbsp;</td>
        <td width='42'><h1 align='right'>Vendor:</h1></td>
        <td width='341'>&nbsp;</td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan='3' valign='top'><table width='373' height='425' border='0' cellpadding='3'>
      <tr>
        <td height='18' colspan='2'><h1>Design Notes: </h1></td>
        </tr>
      <tr>
        <td height='381' colspan='2' valign='top' class='bottom_boarder'>".$designNotes."<br />
          <br />
          <span class='style1'>".$colors."<br />
          <br />
          <span class='style2'>".$paper."</span></span></td>
        </tr>
      
      <tr>
        <td width='116' height='18'><h1>Quantity Requested: </h1></td>
        <td width='239'>".$quantity."</td>
      </tr>
    </table></td>
    <td valign='top'><table width='624' border='0' cellpadding='3'>
        <tr>
          <td width='72'><h1>&nbsp;</h1></td>
          <td width='139'><h1 align='center'>Description</h1></td>
          <td width='124'><h1 align='center'>Qty</h1></td>
          <td width='115'><h1 align='center'>Price</h1></td>
          <td width='132'><h1 align='center'>Total</h1></td>
        </tr>
        <tr>
          <td colspan='5' bgcolor='#E9E9E9'>            <h1 align='left'>Paper:</h1></td>
        </tr>
        <tr>
          <td height='50'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
        </tr>
        <tr>
          <td colspan='5' bgcolor='#E9E9E9'><div align='right'>
            <h1 align='left'>Output:</h1>
          </div></td>
        </tr>
        <tr>
          <td height='50'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
        </tr>
        <tr>
          <td colspan='5' bgcolor='#E9E9E9'><h1 align='left'>Mask:</h1></td>
        </tr>
        <tr>
          <td height='50'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
        </tr>
        <tr>
          <td colspan='5' bgcolor='#E9E9E9'><h1 align='left'>Plates:</h1></td>
        </tr>
        <tr>
          <td height='50'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
        </tr>
        <tr>
          <td colspan='5' bgcolor='#E9E9E9'><h1 align='left'>Miscellaneous:</h1></td>
        </tr>
        <tr>
          <td height='50'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
          <td height='50' class='left_boarder'>&nbsp;</td>
        </tr>
        <tr>
          <td colspan='5' class='bottom_boarder'>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><div align='right'>
            <h1>Grand Total: </h1>
          </div></td>
          <td>&nbsp;</td>
        </tr>
        </table></td>
  </tr>
</table>
</body>
</html>";

$msg="";
$hdr="";

$att = $_FILES['att'];
$att_path = $_FILES['att'] ['tmp_name'];
$att_name = $_FILES['att'] ['name'];
$att_size = $_FILES['att'] ['size'];
$att_type = $_FILES['att'] ['type'];

if (is_uploaded_file($att_path)) { 

	$fp = fopen($att_path, "rb");
	if ($fp==TRUE ) {
		$file = fread($fp, filesize($att_path));
		fclose($fp);
		
		if ( $file) {
			$num = md5(time());
			$str = "=-MuLtIpArT_BoUnDaRy_X{$num}x";

			$file = chunk_split(base64_encode($file));


			$hdr .= "From: $from\n";
			//$hdr .= "X-Mailer: \n\n";
			$hdr .= "MIME-Version: 1.0\n";
			$hdr .= "Content-Type: multipart/alternative; boundary=\"{$str}\"\n";
			

			$msg .= "--{$str}\n";
			$msg .= "Content-Type: text/html; \n";
			$msg .= "X-Mailer: \n\n";
			$msg .= "Content-Transfer-Encoding: 7bit\n";
			$msg .= "\n";
			$msg .= "$htmlVersion \n";
			$msg .= "\n\n\n";
			$msg .= "--{$str}\n";
			$msg .= "Content-Disposition: attachment;  filename=\"{$att_name}\"\n";
			$msg .= "Content-Type: {$att_type};  name=\"{$att_name}\"\n";
			$msg .= "Content-Transfer-Encoding: base64\n";
			$msg .= "\n";
			$msg .= "$file\n\n";
			$msg .= "--{$str}\n";

			$ok = mail($to, $subject, $msg, $hdr, "-f$from" );
			if($ok) {

				echo ("The Request Has Been Sent\n" );

			}else{
				echo("Error:This Request Has Not Been Sent - Error 2");
			}
		} else {
			echo "Error reading upload file. This Request has not been sent";
		}
		
	} else {
		echo "Error opening upload file. This Request has not been sent";
	}
} else{
	echo("Error:This Request Has Not Been Sent - Error 1");
}

?>
Reply With Quote
  #2 (permalink)  
Old 04-20-06, 11:08 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
I would consider using this email class by Patiek:

http://www.programmingtalk.com/showthread.php?t=22506

It takes care of the error check for you, so all you have to do is to create an object and you are good to go.
__________________
Reply With Quote
  #3 (permalink)  
Old 04-20-06, 11:36 AM
arandlett arandlett is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Does the recomeded script send html emails?

Does the recomeded script by Patiek send html emails with the attachment?
Do you know if the html email will be viewable in Outlook?
Reply With Quote
  #4 (permalink)  
Old 04-20-06, 01:10 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Quote:
Originally Posted by arandlett
Does the recomeded script by Patiek send html emails with the attachment?
Do you know if the html email will be viewable in Outlook?
I am not sure about HTML emails, but I know for sure that it does do text emails and attachments. And yes, it will be viewable in Outlook.
__________________
Reply With Quote
  #5 (permalink)  
Old 04-22-06, 07:50 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
Very simple, easy to use php class - http://opensme.org/projects/phpmaile....phpmailer.php
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #6 (permalink)  
Old 04-22-06, 10:08 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Wow! Yeah, that's a good one.

Quote:
Originally Posted by FiRe
Very simple, easy to use php class - http://opensme.org/projects/phpmaile....phpmailer.php
__________________
Reply With Quote
  #7 (permalink)  
Old 04-23-06, 07:25 PM
arandlett arandlett is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Question How to use phpemailer

How do I use the php emailer script. Do I set up variables i need to send to it in the php script(like i have above) or do I just name them in the form and add hidden fields to send the variables like in the common (formmail) script?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to Excel then send as email attachment Moloch PHP 14 01-26-11 03:43 AM
PHP to email attachment problem arandlett PHP 6 01-22-09 01:12 PM
html email eclecticanna New Members & Introductions 3 08-17-05 10:38 PM
Putting PHP into a HTML page? PigeonHead HTML/XHTML/XML 5 01-24-05 02:22 PM
Can PHP place quotes around HTML attributes frdmsun PHP 1 08-17-04 02:12 AM


All times are GMT -5. The time now is 07:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.