473,800 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP to email (with optional attachements) expert required

Hi there,

Previously in my PHP code I was using Sendmail to send out emails to people
in the MySQL DB. The requirement cam along to be able to send attachments
and so I dug around for an easy bit of code that did not need classes and I
could plug easily into my PHP code.

I thought I found one (see bottom of email), however I have since discovered
that as it is, this script has the following disadvantages when compared to
using Sendmail as I used to:

1. Sendmail sent out plaintext emails however if there was text that was
like www.example.com then the code would still appear as a link in many
plain text readers. This does not seem to happen when sent using the below
script. Anyone understand why?
(Note: I use the $Text parameter rather then the $HTML one because I need to
assume customers will only have plain text email readers. I also did try
putting the body of the email into both Text and HTML but I ended up
receiving the email twice with the HTML version losing many carriage returns
etc.).

2. With send mail if the delivery address did not exist, we would get an
email bounce back. This does not seem to happen with below despite my
tweaking attempts. Anyone know why this would be?

I may have some more but issues but wont confuse for now any comments
appreciated and please see the code below.

Thanks


*******Custom - insertable sendmail code - very handy if I could fully get
it to work the way I want it to*****

function
SendMail($From, $FromName,$To,$ ToName,$Subject ,$Text,$Html,$A ttmFiles){
$OB="----=_OuterBoundary _000";
$IB="----=_InnerBoundery _001";
$Html=$Html?$Ht ml:preg_replace ("/\n/","<br>",$T ext)
or die("neither text nor html part present.");
$Text=$Text?$Te xt:"Sorry, but you need an html mailer to read this mail.";
$From or die("sender address missing");
$To or die("recipient address missing");

$headers ="MIME-Version: 1.0\r\n";
$headers.="From : ".$FromName ." <".$From.">\n ";
$headers.="To: ".$ToName." <".$To.">\n" ;
#$headers.="To: ".$To."\n";
#$headers.="Rep ly-To: ".$FromName ." <".$From.">\n ";
#Prioriry 3 = normal 1 = high - apparently s- shouldlook more into thi
#$headers.="X-Priority: 1\n";
#$headers.="X-MSMail-Priority: High\n";
#$headers.="X-MSMail-Priority: Normal\n";
$headers.="X-Mailer: My PHP Mailer\n";
$headers.="Cont ent-Type: multipart/mixed;\n\tbound ary=\"".$OB."\" \n";

//Messages start with text/html alternatives in OB
$Msg ="This is a multi-part message in MIME format.\n";
$Msg.="\n--".$OB."\n";
$Msg.="Content-Type: multipart/alternative;\n\ tboundary=\"".$ IB."\"\n\n";

//plaintext section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/plain;\n\tchars et=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$Msg.=$Text."\n \n";

// html section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/html;\n\tcharse t=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: base64\n\n";
// html goes here
$Msg.=chunk_spl it(base64_encod e($Html))."\n\n ";

// end of IB
$Msg.="\n--".$IB."--\n";

// attachments
if($AttmFiles){
foreach($AttmFi les as $AttmFile){
$patharray = explode ("/", $AttmFile);
$FileName=$path array[count($patharra y)-1];
$Msg.= "\n--".$OB."\n";
$Msg.="Content-Type:
application/octetstream;\n\ tname=\"".$File Name."\"\n";
$Msg.="Content-Transfer-Encoding: base64\n";
$Msg.="Content-Disposition:
attachment;\n\t filename=\"".$F ileName."\"\n\n ";

//file goes here
$fd=fopen ($AttmFile, "r");
$FileContent=fr ead($fd,filesiz e($AttmFile));
fclose ($fd);
$FileContent=ch unk_split(base6 4_encode($FileC ontent));
$Msg.=$FileCont ent;
$Msg.="\n\n";
}
}

//message ends
$Msg.="\n--".$OB."--\n";
#mail($To,$Subj ect,$Msg,$heade rs);
mail("",$Subjec t,$Msg,$headers );
//syslog(LOG_INFO ,"Mail: Message sent to $ToName <$To>");
}
Jul 17 '05 #1
3 1677
Dave Smithz wrote:
Hi there,

Previously in my PHP code I was using Sendmail to send out emails to people
in the MySQL DB. The requirement cam along to be able to send attachments
and so I dug around for an easy bit of code that did not need classes and I
could plug easily into my PHP code.

I thought I found one (see bottom of email), however I have since discovered
that as it is, this script has the following disadvantages when compared to
using Sendmail as I used to:

1. Sendmail sent out plaintext emails however if there was text that was
like www.example.com then the code would still appear as a link in many
plain text readers. This does not seem to happen when sent using the below
script. Anyone understand why? whether a string such as 'www.example.co m' is displayed as an HTML link
depends on the email client ('reader') not on the email.
(Note: I use the $Text parameter rather then the $HTML one because I need to
assume customers will only have plain text email readers. I also did try
putting the body of the email into both Text and HTML but I ended up
receiving the email twice with the HTML version losing many carriage returns
etc.).

2. With send mail if the delivery address did not exist, we would get an
email bounce back. This does not seem to happen with below despite my
tweaking attempts. Anyone know why this would be?

I may have some more but issues but wont confuse for now any comments
appreciated and please see the code below.

Thanks


i'd recommend using phpMailer, available from
http://phpmailer.sourceforge.net/. does the job. simple to use. what
more could you want?

sadara
Jul 17 '05 #2
"Dave Smithz" <SPAM FREE WORLD> wrote in
news:42******** @news1.homechoi ce.co.uk:

I may have some more but issues but wont confuse for now any comments
appreciated and please see the code below.


take five minutes and tweak this to your exact liking:

http://www.phpclasses.org/browse/package/9.html

it's just amazing.
Jul 17 '05 #3

"Sadara" <sa*********@NO WAYdds.nl> wrote in message
news:42******** *************@n ews.xs4all.nl.. .
i'd recommend using phpMailer, available from
http://phpmailer.sourceforge.net/. does the job. simple to use. what
more could you want?

What can I say. So far, so d*rn amazing!!!. I was scared off normally by
the fact that you download lots of files and was not familiar with PHP
classes.

Easy when you try (well seems so, so far).

Thanks
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2645
by: siliconpiNOSPAM | last post by:
Hi, I'm writing a program that should accept the following parameters: XMLfile (required) Logfile (required) /A (append flag, optional) /D 123 (delay value, optional, but # should follow /D immediately) /V 123 (version number, optional, but # should follow /V immediately)
0
3944
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
4
2272
by: JJ | last post by:
Whats the most compatilbe way of sending an email ?- I need to consider that the OS may be win 98/win NT/Win 2000/winXP. I was constructing a mailto command, but the contents of the text file I am using as the subject is too long and gets cut off. I therefore need a method that doesn't use the limitations of mailto (in terms of the length of the subject text) or allows me to add the text file as an attachment. I am using VB 2003. I...
14
3275
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To make things simpler and better readable I'd make all default parameters named parameters so that you can decide for yourself which one to pass and which not, rather than relying on massively overlaoded methods which hopefully provide the best...
1
1455
by: Tookelso | last post by:
Hello, I would like to have a group of elements which are *required* in one context, but each one is *optional* in another context. For example: I have a configuration file which has a <defaultselement. There are 5 settings which *must* be defined in the <defaultssection. The configuration file also has <databaseelements. A database can
2
1604
by: Alan T | last post by:
I recently programming Word application/document in CSharp but got several problem. Any pointer to get started?
7
13475
by: Sam Shrefler | last post by:
I'm working on creating a WebService / WebMethod to receive a record in real time from another system. The record contains about 20 fields. 10 of which aren't required. I was planning on just making a method with 20 parameters. But, I see there is no way to make an "optional" c# parameter. I was just wondering if anyone had an suggestions on how to implement this? The parameters are all different primitive types (int, string,...
1
2470
by: Dave | last post by:
I have multiple forms that will create an object. Basically a energy efficiency measure object. The measure object will have a couple of required properties set but after that it can have 10-20 different fields that are optional per measure. How do I account for the different fields that will be posted from the different forms when I create the measure object? Should I create a constructor method with just the required fields as the...
2
2494
by: kennykenn | last post by:
Hi, Ive producd code to send an email after capturing info off a form,it works fine locally but when i put it live it doesnt work! the code is stopin at 'msg.send' any ideas, here the code! <%
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.