Problems with mail()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
folman
Forum Newbie
Posts: 2
Joined: Tue Feb 01, 2011 3:38 pm

Problems with mail()

Post by folman »

Hi at DevNetwork

I have a problem with the function mail(). Or proberly a problem with the data i put into the function.

I can't make it send mails to CC and BCC.

Here is my script

Code: Select all

				// Mail content
				$message = "dette er en test med æ ø å og Æ Ø Å";
				$subject = "1 test med æ ø å og Æ Ø Å";
							
				    $file = $_SERVER['DOCUMENT_ROOT'] . str_replace("project_mail_data.php" ,"", $_SERVER["SCRIPT_NAME"] . $files[$i]);
				    $file_size = filesize($file);
				    $handle = fopen($file, "r");
				    $content = fread($handle, $file_size);
				    fclose($handle);
				    $content = chunk_split(base64_encode($content));
				    $name = basename($file);
				    $header = "From: DCP Postyr <dcp@postyr.dk>\r\n";
				    $header .= "Reply-To: dcp@postyr.dk\r\n";
				    $headers .= "CC: kdmcc@lortemail.dk\r\n";
					$headers .= "BCC: kdmbcc@lortemail.dk\r\n";
					$headers .= "\r\nX-Mailer: PHP/" . phpversion() . "\r\n";
				    $header .= "MIME-Version: 1.0\r\n";
				    $header .= "Content-Type: multipart/mixed; boundary=\"".md5(uniqid(time()))."\"\r\n\r\n";
				    $header .= "This is a multi-part message in MIME format.\r\n";
				    $header .= "--".md5(uniqid(time()))."\r\n";
				    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
				    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
				    $header .= "--".md5(uniqid(time()))."\r\n";
				    $header .= "Content-Type: application/zip; name=\"".$filename."\"\r\n";
				    $header .= "Content-Transfer-Encoding: base64\r\n";
				    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
				    $header .= $content."\r\n\r\n";
				    $header .= "--".md5(uniqid(time()))."--";
			    if (mail($to, $subject, $message, $header)) {
			        echo "mail send ... OK";
			    } else {
			        echo "mail send ... FEJL!";
			    }
Everything works, except the CC and BCC

Any ideas?

Thanks!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Problems with mail()

Post by AbraCadaver »

I may be off, but I seem to remember that you must use Cc: and Bcc: not CC: and BCC: And I would probably remove the actual email addresses from your post.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Problems with mail()

Post by John Cartwright »

Do yourself a massive favor. Use a mail protocol library such as the famous http://swiftmailer.org . It handles all the intricacies involved in mailing you for, and believe me, there is a lot of weirdness that can happen.
folman
Forum Newbie
Posts: 2
Joined: Tue Feb 01, 2011 3:38 pm

Re: Problems with mail()

Post by folman »

AbraCadaver wrote:I may be off, but I seem to remember that you must use Cc: and Bcc: not CC: and BCC: And I would probably remove the actual email addresses from your post.
Thanks!
Though i figured out the problem.
The cc and bcc was called $headers and not $header.

Worked on that problem for to hours now. I hate when that happens :)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Problems with mail()

Post by AbraCadaver »

folman wrote:
AbraCadaver wrote:I may be off, but I seem to remember that you must use Cc: and Bcc: not CC: and BCC: And I would probably remove the actual email addresses from your post.
Thanks!
Though i figured out the problem.
The cc and bcc was called $headers and not $header.

Worked on that problem for to hours now. I hate when that happens :)
Damn, I missed that! But listen to John.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply