php: mail

php: mail

am 12.02.2008 13:32:51 von germana

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!!!

$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@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-
Content-Type: multipart/alternative; boundary="PHP-alt- $random_hash; ?>"

--PHP-alt-
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

--PHP-alt-
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!


This is something with HTML formatting.



--PHP-alt---

--PHP-mixed-
Content-Type: application/pdf; name="file.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment


--PHP-mixed---

//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 : "Mail
failed
";
?>

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: php: mail

am 15.02.2008 04:09:20 von Manuel Lemos

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/

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php