Hi,

I'm trying to send an image as an attachment using php (via flash) and mail() and i'm getting stuck. I know its possible I think its just my syntax thats wrong. Heres the code I have so far:

<?php
$separator = "\r\n";
$image = <img src="Hype1.jpg">;
$message = "<html><body>"$image"</body></html>" . $separator; //PROBLEM!
$subject=$POST['sender_name']." has sent you a picture from www.hypedafunk.co.uk!";
$subject = wordwrap($subject, 70);
$to = $
POST['email_address'];
$to = wordwrap($to, 70);
$headers .= 'From: HypeDaFunk <info@hypedafunk.co.uk>'.$eol;
$headers .= 'Reply-To: HypeDaFunk <info@hypedafunk.co.uk>'.$eol;
$headers .= 'Return-Path: HypeDaFunk <info@hypedafunk.co.uk>'.$eol;

$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html;charset=ISO-8859-9\n";
$headers .= "X-Priority: 1\n";
$headers .= "Importance: High\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: PHP v".phpversion().$eol;

mail($to, $subject, $message, $headers);
?>

The email sends fine when the img src line is substituted with text so I know that its that line thats the problem with the code. I'd really appreciate someone to tell me what I'm doing wrong.

Many thanks,

Graham

    Hi,

    Thanks for replying.

    I've just tried that and it didn't seem to make any difference - but I can't see why trying to embed an image from http://www.mysite.co.uk/hype1.jpg as opposed to just hype1.jpg would make a difference.

    Is the syntax of $message = "<html><body>"$image"</body></html>" correct? I'm unsure as to whether $image should be in quotation marks as well.

    graham

      Thanks for replying and thanks for the thread.

      Whilst googling for an answer to my problem I came across alot of these classes that are used with mail() - is this the only way to do it? I thought I was just getting the syntax of the attachment line wrong and I kind of wanted to keep thing as simple as possible (just so I understand it all!) but if using the method such as you've described is the only way then I'll do that.

      Graham

        No I'm afraid you have to deal with all that. MIME is bit intimidating at first, but, well,
        after sometime, things get clearer 🙂

        I was a bit disappointed like you the first time I came to this conclusion.

        Sending text email is really easy with the good old mail() function, but having to deal
        with MIME attachment is another story.

        Anyway, you have whole classes to help you, it depends if you want to deal yourself
        with all the gory details or not 🙂

        Things like this :

        http://www.phpguru.org/static/mime.mail.html

        http://www.developer.com/lang/php/article.php/3468701

          Lol.

          I thought that might be the answer! No its fine, its something I need to do and get my head around because the possibilities it opens up are too good to not use!

          Thanks for all your help and giving me a definite answer so don't have to waste my time with something that wasn't going to work anyway!

          Graham

            Hi,

            Ok spent all day working with the code found on http://www.phpguru.org/static/mime.mail.html rooting our various errors and so on and I've finally only got one warning but I'm not quite sure how I should get rid of it:

            Warning: fsockopen() [function.fsockopen]: unable to connect to localhost:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in **************\smtp.php on line 75
            Array ( [0] => Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. [1] => Not connected! )

            Obviously it can't connect properly to the server but I'm not quite sure how I should amend smtp.php in order to make it connect properly. I'm guessing that I'll need some info from my hosting company but can anyone give me some generic guidence as to where I might find the info or what socket I should be opening?

            Thanks,

            Graham

              fsockopen is using port 25, that should be fine.
              SMTP server are answering on port 25.

              So may be there's some firewal mecanism somewhere which prevent your system
              to open a connection on a distant port 25 ? (for security reason, in case your host
              been compromised and used to send spam all around the world that way)

                So your saying the only way to sort this out is to contact my host?? (I really hope not because their tech support is rubbish!!!)

                Graham

                  Well it can also be that the SMTP server you were trying to send a message was down
                  at that time or something like that.

                  Try to send a mail with a regular email client like Thunderbird to the same
                  address at the same time and you will know if it's the SMTP server which
                  have some trouble or your script.

                    Just spoke to tech support and they said I had to use 'intmail.atlas.pipex.net' instead of 'localhost' and that it had to be authenticated.

                    I edited the line in smtp.php from:

                    $this->host = 'localhost';
                    to:
                    $this->host = 'intmail.atlas.pipex.net';

                    and also:

                    $this->helo = 'localhost';
                    to:
                    $this->helo = 'intmail.atlas.pipex.net';

                    is this the right thing to be doing? If so it hasn't made any difference.

                    Also I noticed:

                    $this->authenticated = FALSE;

                    I guess this means it is set to not be authenticated. Is it just a simple matter of:
                    $this->authenticated = TRUE;

                    ???

                    Thanks for all your help with this.

                    Graham

                      Yes for the two 'localhost <-> intmail.atlas.pipex.net' exchanges. That's ok.

                      For the authenticated part, I would say "yes", but the authentification against
                      a SMTP server can be done in various ways, so may be it will not be that easy ?

                      I'm quite sure you will have to also feed the

                      $this->user
                      $this->pass

                      variables too. (values are those used to retrieve your own mail, via your POP/IMAP server)

                      It's past midnight here and I have to get some sleep for tomorrow ... well, today now 🙂

                      See you

                        I now have this in my smtp.php file:

                        $this->authenticated = TRUE;
                        $this->timeout = 5;
                        $this->status = SMTP_STATUS_NOT_CONNECTED;
                        $this->host = 'intmail.atlas.pipex.net';
                        $this->port = 25;
                        $this->helo = 'intmail.atlas.pipex.net';
                        $this->auth = TRUE;
                        $this->user = 'info@**********';
                        $this->pass = '
                        ****';
                        $this->errors = array();

                        But still no joy I'm still getting this warning:

                        Warning: fsockopen() [function.fsockopen]: unable to connect to localhost:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in \filer01\home\hypedafunk.co.uk[url]www.hypedafunk.co.uk\web\content\smtp.php[/url] on line 75
                        Array ( [0] => Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. [1] => Not connected! )

                        Still not quite sure whether this is a problem with my code or my host. I'll contact tech support again but if you guys have any other ideas I'm all ears!

                        Many thanks,

                        Graham

                          Write a Reply...