Page 1 of 1

Problems with mail()

Posted: Tue Feb 01, 2011 3:44 pm
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!

Re: Problems with mail()

Posted: Tue Feb 01, 2011 3:49 pm
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.

Re: Problems with mail()

Posted: Tue Feb 01, 2011 3:52 pm
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.

Re: Problems with mail()

Posted: Tue Feb 01, 2011 3:53 pm
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 :)

Re: Problems with mail()

Posted: Tue Feb 01, 2011 3:59 pm
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.