473,787 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I add BCC: to this PHP mailer please?

I found this basic PHP mailer with file attachment capability. It
works just fine, but I want to add a CC: and BCC: to its output. I
added the $cc & $bcc variables below, but unsure how to implement the
rest. Can someone please help? Thank you - LM

<html>
<head>
<title> Sending Email </title>
</head>
<body>
<?php
// Read POST request params into global vars
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$cc = $_POST['cc'];
$bcc = $_POST['bcc'];

// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];

$headers = "From: $from";

if (is_uploaded_fi le($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt, 'rb');
$data = fread($file,fil esize($fileatt) );
fclose($file);

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Bo undary_x{$semi_ rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mi me_boundary}\"" ;

// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary }\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

// Base64 encode the file data
$data = chunk_split(bas e64_encode($dat a));

// Add file attachment to the message
$message .= "--{$mime_boundary }\n" .
"Content-Type: {$fileatt_type} ;\n" .
" name=\"{$fileat t_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fi leatt_name}\"\n " .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary }--\n";
}

// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
?>
</body>
</html>

Aug 24 '05
12 21181
> Please do not put a whitespace between the CLRF. It violates RFC2822.

I wondered about that. I this is the only case I have ever done so. It
was an example on php.net that I did a quick copy/paste.

Aug 24 '05 #11
* Nerdlance.com:
I wondered about that. I this is the only case I have ever done so. It
was an example on php.net that I did a quick copy/paste.


RFC2822 tells you to seperate (header) lines by CRLF, not by any other
combination of characters. It's mostly a thing of interoperabilit y and
avoiding this is, in the luckiest way, considered harmful.

--
"The sky above the port was the color of television,
tuned to a dead channel." o <http://knurd.de/>
-- William Gibson, Neuromancer, o -- A Geek's View
Chiba City Blues ooo
Aug 24 '05 #12
Larry wrote:
I found this basic PHP mailer with file attachment capability. It
works just fine, but I want to add a CC: and BCC: to its output. I
added the $cc & $bcc variables below, but unsure how to implement the
rest. Can someone please help? Thank you - LM
Apologies if this is already on your to-do list, but you're going to
want to make some changes to that code if it's going to be publicly
accessible. If not expect the spammers to take full advantage of it.
They will.
<html>
<head>
<title> Sending Email </title>
</head>
<body>
<?php
// Read POST request params into global vars
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$cc = $_POST['cc'];
$bcc = $_POST['bcc'];

<snip>

Kelv
--
LoHost
http://www.lohost.com
Aug 25 '05 #13

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

Similar topics

0
1090
by: Hai Nguyen | last post by:
Would anybody please tell me what is this error and what i should do I have 5 files: page1.aspx,page1.aspx.cs; page2.aspx.page2.aspx.cs and page3.cs both page1.aspx.cs and page2.aspx.cs inherit page3 page3.cs is like a library to share common methods I got this error
12
1538
by: 1111111111 | last post by:
I am writing a program that tells users to enter 2 sides of a rectangle. From that the program will output a drwaing of the rectangle using "*"'s... Here is my problem. Say I enter 5 and 10 for the 2 sides.. This is what is output. ********** * * * * * * * **********
4
1171
by: Trint Smith | last post by:
How can I improve this code please? It sometimes produces this error: "Object reference not set to an instance of an object" When I do this: strSQL = "UPDATE TBL_Items SET" & _ " item_itemnumber = " & PrepareStr(Label6.Text) & _ " ,item_itemcurrentbidprice = " & PrepareStr(itemCurrentbidprice) & _ " ,item_itembidhistory = " & PrepareStr(itembidHistory) & _
1
1621
by: omid1980 | last post by:
hi I have an examination and i shuld answer this question please help me. Explain the advantages of using XML with a database for ecommerce sites?
5
2205
by: mohammaditraders | last post by:
Question # 1 Write a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions Cal_percentage() which calculate the percentage of the student by the formula (Ob_marks * 100 )/Total_marks and Display() which show all information of the student. The class should also contain the default constructor which initializes all the data member of...
4
1373
by: isabelle | last post by:
hi, every body.. help me in this program. please!! write a c++ program that converts hexadecimal digit to its corresponding decimal value. input/output: Enter a hexadecimal digit :A The corresponding decimal value:10
13
2614
by: ishakarthika | last post by:
how can i compare the a private variable of a class and a value in the column of a text file. there is a syntax error in my code while comparing. senario is i am getting bus details like busno, source , destination,type of bus, price/head . I should compare the busno which i get through object to the bus no which is present in a .txt file. and contents in the text file is as the format below. |1488|xxx|uuuu|A/c|150....
0
183
by: mayariasxf | last post by:
http://forums.vogue.com.au/member.php?u=91686 tube8 http://forums.vogue.com.au/member.php?u=91688 redtube http://forums.vogue.com.au/member.php?u=91689 pornhub http://forums.vogue.com.au/member.php?u=91690 yobt http://www.dynamicdrive.com/forums/member.php?u=33924 tube8 http://www.dynamicdrive.com/forums/member.php?u=33925 redtube Visit this sites please
0
9655
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
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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
6749
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();...
1
4069
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
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.