|
From: Maria Oliveira on 12 Feb 2008 07:32 Im using this code to sent an email from the server to an email that the user write into a form, with a file attached, BUT it seems not to work. It 'echo' the message 'Mail Sent' but im not reciving any email, i even check on my spam... not in gmail or yahoo or hotmail Thanks!!! <?php $file=$_POST['file']; //define the receiver of the email $to = $_POST['email']; //define the subject of the email $subject = 'Test email with attachment'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: support(a)mycompani.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents($file))); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello World!!! This is simple text email message. --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <h2>Hello World!</h2> <p>This is something with <b>HTML</b> formatting.</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: application/pdf; name="file.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent to: ".$to : "<font style=color:red>Mail failed</font>"; ?>
From: Manuel Lemos on 14 Feb 2008 22:09 Hello, on 02/12/2008 10:32 AM Maria Oliveira said the following: > Im using this code to sent an email from the server to an email that the > user write into a form, with a file attached, BUT it seems not to work. > It 'echo' the message 'Mail Sent' but im not reciving any email, i even > check on my spam... not in gmail or yahoo or hotmail I think your line breaks may be wrong for the platform you are using. That is a common source for problems. It is hard to tell without seeing the actual output of the script, but it is possible that your message is malformed and it is being discarded for not being compliant with the e-mail standards. Personally, I use this MIME message composing and sending class which sends RFC compliant messages and works well for delivering messages to all e-mail services. You may want to try it: http://www.phpclasses.org/mimemessage -- Regards, Manuel Lemos PHP professionals looking for PHP jobs http://www.phpclasses.org/professionals/ PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/
|
Pages: 1 Prev: Concurrency issue on session file on harddisk Next: Installation blues |